Go to Post Originality in Sponsorship can get you a lot of places. - MysterE [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 03-21-2009, 09:59 PM
mgoodell6 mgoodell6 is offline
Registered User
AKA: Mark Goodell
FTC #1902 (Exploding Bacon)
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2005
Location: Orlando, FL
Posts: 3
mgoodell6 is an unknown quantity at this point
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 ("\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);
}
}
  #2   Spotlight this post!  
Unread 03-22-2009, 03:36 PM
Sentient's Avatar
Sentient Sentient is offline
Registered User
FRC #0639 (Code Red)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Ithaca
Posts: 21
Sentient is on a distinguished road
Re: Capturing Camera Images to cRIO

Is cameraImage a pointer?
  #3   Spotlight this post!  
Unread 03-22-2009, 06:55 PM
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,016
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Capturing Camera Images to cRIO

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.

Code:
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.
  #4   Spotlight this post!  
Unread 03-23-2009, 10:47 AM
Ken Streeter's Avatar
Ken Streeter Ken Streeter is offline
Let the MAYHEM begin!
FRC #1519 (Mechanical Mayhem)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Team: Milford, NH; Me: Bedford, NH
Posts: 387
Ken Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond repute
Re: Capturing Camera Images to cRIO

Quote:
Originally Posted by mgoodell6 View Post
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)
2013 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!"
  #5   Spotlight this post!  
Unread 03-26-2009, 06:24 AM
mgoodell6 mgoodell6 is offline
Registered User
AKA: Mark Goodell
FTC #1902 (Exploding Bacon)
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2005
Location: Orlando, FL
Posts: 3
mgoodell6 is an unknown quantity at this point
Re: Capturing Camera Images to cRIO

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


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving images/video from camera (LabVIEW) Chaos in a Can NI LabVIEW 3 08-16-2010 03:21 PM
Connecting Axis camera to cRIO laultima FRC Control System 20 01-21-2009 03:56 PM
Capturing images from a Flash file JohnBoucher IT / Communications 2 12-03-2007 02:14 PM
Capturing Video from camera with Premiere 5.5 sanddrag IT / Communications 14 09-09-2005 03:45 AM


All times are GMT -5. The time now is 10:58 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi