Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2007, 11:40 AM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Works under App but not under Windows service

I have a weard problem, I have created a class and instanciate an object for using his methods... Everything works fine if I use the class under a windows APPLICATION, but when I call the method under a windows service... It's failing...
There must be something wrong. I tried putting some [STAThread] without knowing what it does.
I'm very confused (newbie to .Net also) hey hey !

here's my class code.


using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using Cvb;


namespace TestCorrelateClass
{
    public sealed class MainForm
    {
        public Cvb.Image.IMG cvSourceImage;
        public Cvb.Image.IMG cvLiveImage;
        public Cvb.Minos.TPL cvTemplateImage;
        public double liveHeight;
        public double liveWidth;
        public MainForm()
        {
            writeLogging("Init");
            System.Drawing.Image objImage = System.Drawing.Image.FromFile("c:\\testok91.jpg");
            liveHeight = objImage.Size.Height;
            liveWidth = objImage.Size.Width;
            bool result = Cvb.Image.LoadImageFile("c:\\testok91.jpg", out cvSourceImage);
            writeLogging("Image loaded Source ");
        }
       public bool testCammoved(int X0, int Y0, int X1, int Y1, int treshOld)
        {
            Utilities.TIMEWATCH timerHandle;
            Cvb.Image.TArea area;
            double stopTime;
            int density = 250 + (treshOld * 75);
            double diffPixels = treshOld * 1.5;
            double xPos, yPos, quality, dX, dY;
            string name;
            area.X0 = 0;
            area.X1 = 0;
            area.X2 = liveWidth;
            area.Y0 = 0;
            area.Y1 = liveHeight;
            area.Y2 = 0;
            int aid;
            Minos.RESULTS results;
            Utilities.TWCreate(out timerHandle);
            Utilities.TWStartStopWatch(timerHandle, 0);
            Minos.Correlation.OptCorrelations(cvLiveImage, cvTemplateImage, 0, 0, density, area, 0.5, 4, 20, null, IntPtr.Zero, out results);
            Utilities.TWReadStopWatch(timerHandle, 0, out stopTime);
            Utilities.TWDestroy(timerHandle);
            int resultsCount = Minos.SearchResultsCount(results);
            writeLogging("Count from test = " + resultsCount.ToString());
            for (int i = 0; i < resultsCount; i++)
            {
                Minos.SearchResult(results, i, out quality, out xPos, out yPos, out dX, out dY, out name, out aid);
            }
            if (resultsCount == 0)
            {
                return true;
            }
            else
            {
                Minos.SortResultsByQuality(results);
                Minos.SearchResult(results, 0, out quality, out xPos, out yPos, out dX, out dY, out name, out aid);
                //cvSourceDisplay.StatusUserText = String.Format(" Processing time: {0:0.0#} ms", stopTime);
                if (((System.Math.Abs(xPos - X0) <= diffPixels) && (System.Math.Abs(yPos - Y0) <= diffPixels)) && (quality >= treshOld * 0.10))
                    return false;// display it
            }
            return true;
        }

        private void writeLogging(string theString)
        {
            FileStream file = new FileStream("c:\\debug.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(file);
            sw.Write(theString + "\n");
            sw.Close();
            file.Close();
        }
        public bool checkCamMoved(int X0, int Y0, int X1, int Y1, int treshOld, string sourceImage, string liveImage)
        {
            writeLogging("checkCamMoved");
            System.Drawing.Image objImage = System.Drawing.Image.FromFile(liveImage);
            liveHeight = objImage.Size.Height;
            liveWidth = objImage.Size.Width;
            bool result = Cvb.Image.LoadImageFile(@sourceImage, out cvSourceImage);
            writeLogging("Image loaded Source ");
            Cvb.Image.LoadImageFile(@liveImage, out cvLiveImage);
            writeLogging("Image loaded written " + Cvb.Image.WriteImageFile(cvSourceImage, "c:\\output.jpg"));
            setTemplate(X0, Y0, X1, Y1);//8 treshold
            writeLogging("Template Created");
            if (testCammoved(X0, Y0, X1, Y1, treshOld))
                return true;
            else
                return false;

        }
        public void setTemplate(int X0, int Y0, int X1, int Y1)
        {
            Cvb.Image.TArea area;
            Image.IMG templateImage;
            cvTemplateImage = new Cvb.Minos.TPL();
            area.X0 = area.X1 = area.X2 = area.Y0 = area.Y1 = area.Y2 = 0;
            area.X0 = X0;
            area.Y0 = Y0;
            area.X1 = X0;
            area.Y1 = Y1;
            area.X2 = X1;
            area.Y2 = Y0;
            Cvb.Image.CreateSubImage(cvSourceImage, area, out templateImage);
            // set origin to to-left
            Image.SetImageOrigin(templateImage, 0, 0);
            // set image to display
            cvTemplateImage = (Cvb.Minos.TPL)(templateImage.ToIntPtr());
            }
    }
}







Similar Threads
Thread Thread Starter Forum Replies Last Post
Impersonate with windows service for Service A/C vinod_yadav1919 C# 0 October 18th, 2008 02:29 PM
Accessing Windows service from a windows app sajid08 C# 1 October 6th, 2006 10:25 AM
Calling windows app from web service .. André G.Agayby Classic ASP Basics 1 August 1st, 2005 05:57 PM
Windows app works but Web doesn't? ns130 Crystal Reports 0 January 21st, 2005 12:41 PM
Running a VB6 app as a service adman Pro VB 6 3 April 6th, 2004 02:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.