Beispiel #1
0
HistogramReport* frcHistogram(const Image* image, int numClasses, float min, float max, Rect rect)
{
	int success; 
	int fillValue = 1;
	
	/* create the region of interest */
	ROI* pRoi = imaqCreateROI();
	success = imaqAddRectContour(pRoi, rect); 
	if ( !success )	{ GetLastVisionError(); return NULL; }	

	/* make a mask from the ROI */
	Image* pMask = frcCreateImage(IMAQ_IMAGE_U8);
	success = imaqROIToMask(pMask, pRoi, fillValue, NULL, NULL);
	if ( !success )	{ 
		GetLastVisionError(); 
		frcDispose(__FUNCTION__, pRoi, NULL); 
		return NULL; 
	}	
	
	/* get a histogram report */
	HistogramReport* pHr = NULL;
	pHr = imaqHistogram(image, numClasses, min, max, pMask); 
	
	/* clean up */
	frcDispose(__FUNCTION__, pRoi, pMask, NULL); 
	
	return pHr;
}
/** 
 * Get an image from camera and store it on the cRIO 
 * @param imageName stored on home directory of cRIO ( "/" )
 **/
void TakeSnapshot(char* imageName)	
{	
	/* allow writing to vxWorks target */
	//Priv_SetWriteFileAllowed(1);   	
	
	DPRINTF(LOG_DEBUG, "taking a SNAPSHOT ");
	Image* cameraImage = frcCreateImage(IMAQ_IMAGE_HSL);
	if (!cameraImage) {
		DPRINTF (LOG_INFO,"frcCreateImage failed - errorcode %i",GetLastVisionError()); 
	}
	
	if ( !camera166->GetImage(cameraImage) ) {
		DPRINTF (LOG_INFO,"\nImage Acquisition from camera failed %i", GetLastVisionError());
	} else { 
		DPRINTF (LOG_DEBUG, "calling frcWriteImage for %s", imageName);
		if (!frcWriteImage(cameraImage, imageName) ) { 
			int errCode = GetLastVisionError();
			DPRINTF (LOG_INFO,"frcWriteImage failed - errorcode %i", errCode);
			char *errString = GetVisionErrorText(errCode);
			DPRINTF (LOG_INFO,"errString= %s", errString);
		} else { 
			DPRINTF (LOG_INFO,"\n>>>>> Saved image to %s", imageName);	
			// always dispose of image objects when done
			frcDispose(cameraImage);
		}
	}
}
Beispiel #3
0
void Michael1::Autonomous(void)
{
	GetWatchdog().SetEnabled(false);
	while(IsAutonomous()){
		img = frcCreateImage(IMAQ_IMAGE_HSL);
		GetImage(img, NULL);
		    bool pin[5];
			pin[0] = pin[1] = pin[2] = pin[3] = pin[4] = false;
			
			int camZone = checkzone(1); // 1 is red, 2 is green
			if (camZone > -1){
				pin[camZone] = true;
			}
			printf("camzone = %d", camZone);
			ds->SetDigitalOut(1, pin[0]);
			ds->SetDigitalOut(2, pin[1]);
			ds->SetDigitalOut(3, pin[2]);
			ds->SetDigitalOut(4, pin[3]);
			ds->SetDigitalOut(5, pin[4]);
		frcDispose(img);
		Wait(0.1);
	}
	printf("end auton");
}
Beispiel #4
0
/**
* @brief Search for a color. Supports IMAQ_IMAGE_HSL and IMAQ_IMAGE_RGB. 
* @param mode Color mode, either IMAQ_HSL or IMAQ_RGB
* @param plane1Range The range for the first plane (hue or red)
* @param plane2Range The range for the second plane (saturation or green)
* @param plane3Range The range for the third plane (luminance or blue)
* @param trackReport Values for tracking: center of particle, particle size, etc
* @param colorReport Color charactaristics of the particle
* @param rect Rectangle to confine search to
* @return 0 = error
*/
int FindColor(ColorMode mode, const Range* plane1Range, const Range* plane2Range, 
		const Range* plane3Range, ParticleAnalysisReport *trackReport, 
		ColorReport *colorReport, Rect rect)
{
	int errorCode = 0;
	int success = 0;
	
	/* create an image object */
	Image* cameraImage = frcCreateImage(IMAQ_IMAGE_HSL);
	if (!cameraImage)  { return success; }
	
	/* get image from camera - if the camera has not finished initializing,
	 * this will fail 
	 */
	double imageTime;
	success = GetImage(cameraImage, &imageTime);
	if (!success){
		DPRINTF(LOG_INFO, "No camera Image available Error = %i %s", 
				errorCode, GetVisionErrorText(errorCode));
		frcDispose(cameraImage); 
		imaqSetError(errorCode, __FUNCTION__);	//reset error code for the caller	
		return success;		
	}	
	
	/* save a copy of the image to another image for color thresholding later */
	Image* histImage = frcCreateImage(IMAQ_IMAGE_HSL);
	if (!histImage)  { frcDispose(cameraImage); return success; }
	success = frcCopyImage(histImage,cameraImage);
	if ( !success )	{ 
		errorCode = GetLastVisionError(); 
		frcDispose(__FUNCTION__,cameraImage,histImage,NULL); 
		return success; 
	}	
	
	/* Color threshold the image */
	success = frcColorThreshold(cameraImage, cameraImage, mode, plane1Range, plane2Range, plane3Range);
	if ( !success )	{ 
		errorCode = GetLastVisionError(); 
		DPRINTF (LOG_DEBUG, "Error = %i  %s ", errorCode, GetVisionErrorText(errorCode));
		frcDispose(__FUNCTION__,cameraImage,histImage,NULL); 
		return success; 
	}	

	int largestParticleIndex = 0;
	success = GetLargestParticle(cameraImage, &largestParticleIndex, rect );
	if ( !success )	{
		errorCode = GetLastVisionError(); 
		DPRINTF (LOG_DEBUG, "Error after GetLargestParticle = %i  %s ", errorCode, GetVisionErrorText(errorCode));
		frcDispose(__FUNCTION__,cameraImage,histImage,NULL); 
		imaqSetError(ERR_COLOR_NOT_FOUND, __FUNCTION__);
		return success; 
	}
	DPRINTF(LOG_INFO, "largestParticleIndex = %i\n", largestParticleIndex);

	/* Particles were found  */
		/* 
		 * Fill in report information for largest particle found
		 */
		success = frcParticleAnalysis(cameraImage, largestParticleIndex, trackReport);
		trackReport->imageTimestamp = imageTime;
		
		/* clean up */
		if (!success) {frcDispose(__FUNCTION__,cameraImage,histImage,NULL); return success;}
		
		/* particle color statistics */
		/* only if a color report requested */
		if (colorReport != NULL)
		{
			/* first filter out the other particles */
			ParticleFilterCriteria2 criteria;
			ParticleFilterOptions* options = NULL;
			Rect rect;
			int numParticles;
			success = frcParticleFilter(cameraImage, cameraImage, &criteria, 1, options, 
					rect, &numParticles);
			if ( !success )	{ 
				DPRINTF(LOG_INFO, "frcParticleFilter errorCode %i", GetLastVisionError()); 
			}	
					
			/* histogram the original image using the thresholded image as a mask */
			int numClasses = 10; //how many classes?
			ColorHistogramReport* chrep = imaqColorHistogram2(histImage, numClasses, IMAQ_HSL, 
						NULL, cameraImage);
			if (chrep == NULL) { 
				DPRINTF(LOG_INFO, "NULL Color Histogram");
				errorCode = GetLastVisionError(); 
			} else {
				colorReport->particleHueMax = chrep->plane1.max;
				colorReport->particleHueMin = chrep->plane1.min;
				colorReport->particleHueMean = chrep->plane1.mean;
				colorReport->particleSatMax = chrep->plane2.max;
				colorReport->particleSatMin  = chrep->plane2.min;
				colorReport->particleSatMean = chrep->plane2.mean;
				colorReport->particleLumMax = chrep->plane3.max;
				colorReport->particleLumMin = chrep->plane3.min;
				colorReport->particleLumMean = chrep->plane3.mean;
				colorReport->numberParticlesFound = numParticles;
				frcDispose(chrep); 
			}
		}

	/* clean up */
	frcDispose(__FUNCTION__,cameraImage,histImage,NULL); 
	
	return success;	
}
Beispiel #5
0
/**
* @brief Search for color particles. Supports IMAQ_IMAGE_HSL and IMAQ_IMAGE_RGB. 
* @param mode Color mode, either IMAQ_HSL or IMAQ_RGB
* @param plane1Range The range for the first plane (hue or red)
* @param plane2Range The range for the second plane (saturation or green)
* @param plane3Range The range for the third plane (luminance or blue)
* @param hitReport Contains array of numberHits largest targets
* @param rect Rectangle to confine search to
* @param numberHitsRequested maximum number to return
* @return 0 = error
*/
int FindColorHits(ColorMode mode, const Range* plane1Range, const Range* plane2Range, 
		const Range* plane3Range, ImageHits* hitReport, Rect rect, 
		int numberHitsRequested)
{
	char funcName[]="FindColorHits";
	int errorCode = 0;
	int success = 0;
	/* fixed limit to number of hits processed
	 * larger # takes more processing time but can eliminate failure due to 
	 * interference for instance, a red or green area in the stands or 
	 * closer targets of the wrong alliance
	*/
	if (numberHitsRequested > FRC_MAX_HITS)  numberHitsRequested = FRC_MAX_HITS;
			
	/* create an image object */
	Image* cameraImage = frcCreateImage(IMAQ_IMAGE_HSL);
	if (!cameraImage)  { return success; }

	/* get image from camera - if the camera has not finished initializing,
	 * this will fail */
	success = GetImage(cameraImage,NULL);
	if (!success){
		DPRINTF(LOG_INFO, "No camera Image available Error = %i %s", 
				errorCode, GetVisionErrorText(errorCode));
		frcDispose(cameraImage); 
		imaqSetError(errorCode, funcName);	//reset error code for the caller	
		return success;		
	}	

	/* Color threshold the image */
	success = frcColorThreshold(cameraImage, cameraImage, mode, plane1Range, plane2Range, plane3Range);
	if ( !success )	{ 
		errorCode = GetLastVisionError(); 
		DPRINTF (LOG_DEBUG, "Error = %i  %s ", errorCode, GetVisionErrorText(errorCode));
		frcDispose(funcName,cameraImage,NULL); 
		return success; 
	}	
	/* get largest particles that meet criteria */
	/* GetLargestParticles fills out only the indices in the hitReport */
	success = GetLargestParticles(cameraImage, hitReport, rect, numberHitsRequested);
	if ( !success )	{
		errorCode = GetLastVisionError(); 
		DPRINTF (LOG_DEBUG, "Error after GetLargestParticles=%i  %s ", errorCode, GetVisionErrorText(errorCode));
		frcDispose(funcName,cameraImage,NULL); 
		imaqSetError(ERR_COLOR_NOT_FOUND, funcName);
		return success; 
	}
	if (hitReport->numberOfHits==0) {
		imaqSetError(ERR_COLOR_NOT_FOUND, funcName);
		frcDispose(funcName,cameraImage,NULL); 
		return 0; 
	}
	//DPRINTF(LOG_INFO, "number hits found = %i\n", hitReport->numberOfHits);	
	
	/* Particles were found --
	 * Fill in report information for the largest particles 
	 */	
	double imageTime = GetTime();
	for (int i=0; i<hitReport->numberOfHits; ++i) {
		hitReport->pars[i].imageTimestamp = imageTime;	
		success = frcParticleAnalysis(cameraImage, hitReport->indices[i], &hitReport->pars[i]);
	}
	/* clean up */
	frcDispose(funcName,cameraImage,NULL); 
	
	return success;	
}