Quote:
Originally Posted by mgoodell6
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 ("\nCamera Acquisition failed");
} else {
if (!frcWriteImage(cameraImage, "image.jpeg") ) {
printf ("frcWriteImage failed");
} else {
printf ("\n>>>>> Saved image to %s", "image.jpeg") );
// always dispose of image objects when done
frcDispose(cameraImage);
}
}
|
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.
Code:
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, "\nCamera 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);
}
}
__________________
Ken Streeter - Team 1519 - Mechanical Mayhem (Milford Area Youth Homeschoolers Enriching Minds)
2015 NE District Winners with 195 & 2067, 125 & 1786, 230 & 4908, and 95 & 1307
2013 World Finalists & Archimedes Division Winners with 33 & 469
2013 & 2012 North Carolina Regional Winners with teams 435 & 4828 and 1311 & 2642
2011, 2010, 2006 Granite State Regional Winners with teams 175 & 176, 1073 & 1058, and 1276 & 133
Team 1519 Video Gallery - including Chairman's Video, and the infamous "Speed Racer!"