Capturing Camera Images to cRIO

I have not been able to get the frcWriteImage() function to work. I am using code from the WindRiver camera example but receive a frcWriteImage failed each time I try to save an image. Any help with this would be appreciated.

Here is the code I am using

if ( !GetImage (cameraImage,NULL) ) {
printf ("
Camera Acquisition failed");
} else {
if (!frcWriteImage(cameraImage, “image.jpeg”) ) {
printf (“frcWriteImage failed”);
} else {
printf ("
>>>>> Saved image to %s", “image.jpeg”) );
// always dispose of image objects when done
frcDispose(cameraImage);
}
}

Is cameraImage a pointer?

Not only do we have code that does this, but I took home the school laptop from the waterloo regional, so I have it on me. This is debug code that isn’t critical, so forgive the lack of error checking and memory-freeing.


void SavePictures(TrackingThreshold& tGreen, TrackingThreshold& tPink)
{
  Image* cameraImage = frcCreateImage(IMAQ_IMAGE_HSL);
  GetImage(cameraImage, NULL);
  Image* thresImage = frcCreateImage(IMAQ_IMAGE_HSL);
  frcColorThreshold(thresImage,cameraImage,IMAQ_HSL,&tGreen.hue,&tGreen.saturation,&tGreen.luminance);
  frcWriteImage(thresImage,"green.jpg");
  frcColorThreshold(thresImage,cameraImage,IMAQ_HSL,&tPink.hue,&tPink.saturation, &tPink.luminance);
  frcWriteImage(thresImage,"pink.jpg");
  frcWriteImage(cameraImage,"raw.jpg");
}

This was copied by hand from our code on the laptop, so it probably has some typos. I think the only thing different is that you were not frcCreateImage-ing your image to allocate it.

If you do the thresholding stuff like we did, one note is that you should modify frcColorThreshold so that it sets the “on” color value to something other than 1 (the default in WPILib) so it is easy to see the colors in the thresholded images. We spent quite awhile debugging our thresholding, saying “why are we getting pure-black images” until we realized that they only appeared black, and actually contained data.

My first guess as to the problem is that you may need to supply a full path to the filename. (i.e. /image.jpeg )

Second guess is that you need to allocate storage for cameraImage prior to the above code. (e.g., you need to use “frcCreateImage(IMAQ_IMAGE_HSL)”)

Third guess is that way back once upon a time, vxWorks FAT filesystems had problems with file extensions of longer than 3 characters, so switching to a .jpg extension might help.

In any case, as an example of working code, below is the code that we are using to capture snapshots. The below code is “cut and paste” directly out of our code, so it doesn’t contain any typos.


void TwoColorTracker::Snapshot() {
	
	Image* cameraImage;
	char funcName]="Snapshot";
	int retval;
	int errorCode = 0;
	
	// Put image in root directory. If another directory is used
	// it must exist on the cRIO.
	char* imageName = "/viewxxx.png"; 		
	static int imageNum = 1;
	printf("test ");
	// Camera Snapshot code
	if (imageNum < 6 ) {
		printf("test2 ");
		sprintf(imageName,"/view%d.png",imageNum);
		imageNum++;
		//printf("taking a SNAPSHOT ");
		cameraImage = frcCreateImage(IMAQ_IMAGE_HSL);
		if (!cameraImage)  {
			errorCode = GetLastVisionError();
			DPRINTF(LOG_INFO, "Unable to create %s Error = %i %s", imageName, errorCode, GetVisionErrorText(errorCode));
			return;
		}
		
		if ( !GetImage(cameraImage, NULL) ) {
			DPRINTF(LOG_INFO, "
Camera Acquisition failed %i", GetLastVisionError() );
		} else {
			retval = frcWriteImage(cameraImage, imageName);
			if ( retval ) { 
				printf ("frcWriteImage succeeded.");
			} else {
				//errorCode = GetLastVisionError();
				//DPRINTF(LOG_INFO, "frcWriteImage failed, Error = %i %s", imageName, errorCode, GetVisionErrorText(errorCode));
				printf ("frcWriteImage '%s' failed.", imageName);
			}
		}
		frcDispose(funcName, cameraImage, NULL); 
	}
}

Thanks
We implement this code and it is working like a charm.