02-04-2010 01:17 PM
I have the following code in C#:
private void ExtractColor(CWIMAQImage SourceImage, CWIMAQImage DestinationImage)
Solved! Go to Solution.
02-05-2010 05:18 AM
02-05-2010 12:03 PM
It's the strangest thing. I know the source and destination images are OK because this method works perfectly the first time. But the second time, with literally NO code in between, applied to exact copies of the image used the first time, it fails.
The source image is RGB and I use the source also as the destination so it gets over-written. It looks like this:
CWIMAQImage Original = new CWIMAQImage();
CWIMAQImage Image1 = Original;
CWIMAQImage Image2 = Original;
ExtractColor(Image1,Image1);
ExtractColor(Image2,Image2); //Fails Here
02-05-2010 12:04 PM
02-05-2010 02:10 PM
02-08-2010 10:08 AM
I have seen this before. You are creating the images in one format (grayscale, color) and during your process it is getting converted to a different format. The second time through the loop, it is still the new format, which is not compatible with the first function.
An example where I had this problem is reading a color image from a camera, then converting it to a grayscale image for processing. The second time through the loop, the grayscale image was not the proper format to read a color image.
The solution to this problem is usually to use a separate destination image in the new format during processing. In my case, I created a grayscale image that was used as the destination image during the conversion. This way, I still had a color image for acquisition and a grayscale image for processing.
Bruce
02-08-2010 10:33 AM
02-08-2010 11:13 AM
I'm not sure how it works in C#, but in LabVIEW if you set Image1 = Original and Image2 = Original, they are still both pointing to the same image. You aren't actually making a copy of the data, just the pointer.
Is there a way to check what format your images are when they enter the subroutine? Can you check if they are color, grayscale, etc.? I would be willing the bet the format of one changes between the calls.
Bruce
02-08-2010 11:17 AM - edited 02-08-2010 11:18 AM
I just looked at your code again, and now I am sure of it. Image1 and Image2 are pointing to the same image as Original. Since you are using them as the destination images, they are getting overwritten. Your code is just like the following:
ExtractColor(Original, Original) // Original has now been converted from color to grayscale
ExtractColor(Original, Original) // Can't convert grayscale image, needs to be color - error!!
Bruce
02-08-2010 11:29 AM
Aha! You are right.
So if I do the following it works:
CWIMAQImage OriginalImage = new CWIMAQImage();
AcquirePixelImage(OriginalImage);
CWIMAQImage ImageForDefectFinding = new CWIMAQImage();
ExtractColor(OriginalImage, ImageForDefectFinding);
CWIMAQImage ImageForEdgeFinding = new CWIMAQImage();
ExtractColor(OriginalImage, ImageForEdgeFinding);
EdgeFilter(ImageForEdgeFinding, ImageForEdgeFinding);/**/
Or, alternately I could have instantiated the latter two image objects, then COPIED the original to them and processed them appropriately.
Thanks!