コード例 #1
0
CvAdaptiveSkinDetector::Histogram::Histogram()
{
    int histogramSize[] = { HistogramSize };
    float range[] = { GSD_HUE_LT, GSD_HUE_UT };
    float *ranges[] = { range };
    fHistogram = cvCreateHist(1, histogramSize, CV_HIST_ARRAY, ranges, 1);
    cvClearHist(fHistogram);
};
コード例 #2
0
// ------------------------------------------------------------------------
LABHistogram2D::LABHistogram2D(void) {
	/* hue varies from 0 (~0°red) to 180 (~360°red again) */
	/* saturation varies from 0 (black-gray-white) to 255 (pure spectrum color) */
    int hist_size[] = {a_bins, b_bins};
	float a_ranges[] = { (float)a_min, (float)a_max }; /* A varies from a_min to a_max */
	float b_ranges[] = { (float)b_min, (float)b_max }; /* B varies from b_min to b_max */
	float* ranges[] = { a_ranges, b_ranges };
 	h = cvCreateHist( 2, hist_size, CV_HIST_ARRAY, ranges, 1 );
	cvClearHist(h);
}
コード例 #3
0
ファイル: gui.c プロジェクト: Astrocoderguy/openStarStack
void UpdateButton(GtkObject *object, gpointer user_data) {

	int 		numBins = 256;
	float 		range[] = {0, 255};
	float 		*ranges[] = { range };


	cvReleaseImage(&imgStack8bit);
	imgStack8bit = AdjustHistogram(imgStack, (float)gtk_adjustment_get_value(adjHistLow), (float)gtk_adjustment_get_value(adjHistHigh));
	UpdateMainImage(imgStack8bit);	

	//Generate histogram from 8bit stacked image
	hist = cvCreateHist(1, &numBins, CV_HIST_ARRAY, ranges, 1);
	cvClearHist(hist);
	
	imgRed = cvCreateImage(cvGetSize(imgStack8bit), 8, 1);
	imgGreen = cvCreateImage(cvGetSize(imgStack8bit), 8, 1);
	imgBlue = cvCreateImage(cvGetSize(imgStack8bit), 8, 1);

	cvSplit(imgStack8bit, imgBlue, imgGreen, imgRed, NULL);

	cvCalcHist(&imgRed, hist, 0, 0);
	imgHistRed = DrawHistogram(hist,1,1);
	cvClearHist(hist);

	cvCalcHist(&imgGreen, hist, 0, 0);
	imgHistGreen = DrawHistogram(hist,1,1);
	cvClearHist(hist);
 
	cvCalcHist(&imgBlue, hist, 0, 0);
	imgHistBlue = DrawHistogram(hist,1,1);
 	cvClearHist(hist);

	//Display the histogram images
	UpdateRedHistImage(imgHistRed);
	UpdateGreenHistImage(imgHistGreen);	 
	UpdateBlueHistImage(imgHistBlue);	 


}
コード例 #4
0
ファイル: cria_arquivo.c プロジェクト: RxDx/Photomosaic
void maxHSV(IplImage *img, No *imagem){
	/* variaveis do histograma */
	int numBins = 256;
	float range[] = {0, 255};
	float *ranges[] = {range};
	
	/* cria um histograma */
	CvHistogram *hist = cvCreateHist(1, &numBins, CV_HIST_ARRAY, ranges, 1);
	cvClearHist(hist);
	
	/* aloca as imagens auxiliares */
	IplImage *imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
	IplImage *imgH = cvCreateImage(cvGetSize(img), 8, 1);
	IplImage *imgS = cvCreateImage(cvGetSize(img), 8, 1);
	IplImage *imgV = cvCreateImage(cvGetSize(img), 8, 1);

	cvCvtColor(img, imgHSV, CV_BGR2HSV);			// converte a img (RGB) para imgHSV (HSV)
	cvSplit(imgHSV, imgH, imgS, imgV, NULL);		// separa os canais da imgHSV
	
	cvCalcHist(&imgH, hist, 0, 0);					// calcula o histograma da imgH
	cvGetMinMaxHistValue(hist, NULL, NULL, NULL, &imagem->max_h); // coleta a cor dominante
	cvClearHist(hist);
	
	cvCalcHist(&imgS, hist, 0, 0);
	cvGetMinMaxHistValue(hist, NULL, NULL, NULL, &imagem->max_s);
	cvClearHist(hist);
	
	cvCalcHist(&imgV, hist, 0, 0);
	cvGetMinMaxHistValue(hist, NULL, NULL, NULL, &imagem->max_v);
	cvClearHist(hist);
	
	/* libera as imagens auxiliares */
	cvReleaseImage(&imgHSV);
	cvReleaseImage(&imgH);
	cvReleaseImage(&imgS);
	cvReleaseImage(&imgV);
}
コード例 #5
0
void MultiCamshiftUI::updateEventState() {
  if (!SDL_GetVideoSurface())
    return;

  Uint8 *keystate = SDL_GetKeyState(NULL);
  int mouse_x, mouse_y, mouse_camera, mouse_buttons;

  /* If we don't discover a good reason to use the sample square below, don't */
  draw_sample_square = false;
  sample_from_sample_square = false;

  /* The spacebar just shows the rectangle */
  if (keystate[' '])
    draw_sample_square = true;

  /* Get the current sampling rect, centered on the mouse cursor */
  cv_sdl_get_mouse_state(&mouse_camera, &mouse_x, &mouse_y, &mouse_buttons);
  mouse_camera %= n_cameras;

  sample_square_camera = mouse_camera;
  sample_square.x = mouse_x - sample_square_size/2;
  sample_square.y = mouse_y - sample_square_size/2;
  sample_square.width = sample_square_size;
  sample_square.height = sample_square_size;
  if (sample_square.x < 0) sample_square.x = 0;
  if (sample_square.y < 0) sample_square.y = 0;
  if (sample_square.x > image_size.width - sample_square.width - 1)
    sample_square.x = image_size.width - sample_square.width - 1;
  if (sample_square.y > image_size.height - sample_square.height - 1)
    sample_square.y = image_size.height - sample_square.height - 1;

  /* The right mouse button clears our histogram */
  if (mouse_buttons & SDL_BUTTON(3)) {
    cvClearHist(histograms[mouse_camera]);
  }

  /* If the left mouse button is down, use this image to collect samples towards a
   * reference histogram for the object we're trying to track.
   */
  if (mouse_buttons & SDL_BUTTON(1)) {
    sample_from_sample_square = true;
    draw_sample_square = true;
  }
}
コード例 #6
0
ファイル: gui.c プロジェクト: Astrocoderguy/openStarStack
void GuiInit(char *guiFilename) {
	GtkBuilder      *builder; 
	GtkWidget       *window;
   	GtkLabel	*labelStatus;

	int 		numBins = 256;
	float 		range[] = {0, 255};
	float 		*ranges[] = { range };

    	builder = gtk_builder_new();
    	gtk_builder_add_from_file(builder, guiFilename, NULL);
	//Assign all the widgets
    	window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
    	imageMain = GTK_WIDGET(gtk_builder_get_object(builder, "imageMain"));
    	
    	imageRedHist = GTK_WIDGET(gtk_builder_get_object(builder, "imageRedHist"));
    	imageGreenHist = GTK_WIDGET(gtk_builder_get_object(builder, "imageGreenHist"));
    	imageBlueHist = GTK_WIDGET(gtk_builder_get_object(builder, "imageBlueHist"));

	labelStatus = GTK_WIDGET(gtk_builder_get_object(builder, "labelStatus"));
    	adjHistLow = GTK_WIDGET(gtk_builder_get_object(builder, "adjHistLow"));
    	adjHistHigh = GTK_WIDGET(gtk_builder_get_object(builder, "adjHistHigh"));
	txtMinHist = GTK_WIDGET(gtk_builder_get_object(builder, "txtMinHist"));
	txtMaxHist = GTK_WIDGET(gtk_builder_get_object(builder, "txtMaxHist"));
	//Assign all the function calls
	gtk_builder_connect_signals(builder, NULL);
	//unreference the builder object
    	g_object_unref(G_OBJECT(builder));

	gtk_widget_show(window);               

	gtk_label_set_text(labelStatus, ""); 
	//convert stacked image to 8bit image
	imgStack8bit = AdjustHistogram(imgStack, (float)0.0, (float)255.0);

	//Generate histogram from 8bit stacked image
	
	hist = cvCreateHist(1, &numBins, CV_HIST_ARRAY, ranges, 1);
	cvClearHist(hist);
	
	imgRed = cvCreateImage(cvGetSize(imgStack8bit), 8, 1);
	imgGreen = cvCreateImage(cvGetSize(imgStack8bit), 8, 1);
	imgBlue = cvCreateImage(cvGetSize(imgStack8bit), 8, 1);

	cvSplit(imgStack8bit, imgBlue, imgGreen, imgRed, NULL);

	cvCalcHist(&imgRed, hist, 0, 0);
	imgHistRed = DrawHistogram(hist,1,1);
	cvClearHist(hist);

	cvCalcHist(&imgGreen, hist, 0, 0);
	imgHistGreen = DrawHistogram(hist,1,1);
	cvClearHist(hist);
 
	cvCalcHist(&imgBlue, hist, 0, 0);
	imgHistBlue = DrawHistogram(hist,1,1);
 	cvClearHist(hist);
	
	//Display the histogram images
	UpdateRedHistImage(imgHistRed);
	UpdateGreenHistImage(imgHistGreen);	 
	UpdateBlueHistImage(imgHistBlue);	 

	//Update the main image with the scaled stack image
	UpdateMainImage(imgStack8bit);	 

		 
	//Enter the GUI main
	gtk_main();
}
コード例 #7
0
int main(int argc, char *argv[])
{
    IplImage* img = cvLoadImage("lowContrastPollen.jpg");
	//IplImage* img = cvLoadImage("darkpollen.jpg");

    setbuf(stdout, NULL);
    if(!img){
      printf("Could not load image file: %s\n",argv[1]);
      exit(0);
    }
    int height,width,step,channels;


    // get the image data
    height    = img->height;
    width     = img->width;
    step      = img->widthStep;
    channels  = img->nChannels;

    // Checking...
    printf("Processing a %dx%d image with %d channels\n",height,width,channels);

    // Histogram.
    int numBins = 256;
    float range[] = {0, 255};
    float *ranges[] = { range };
    CvHistogram *hist = cvCreateHist(1, &numBins, CV_HIST_ARRAY, ranges, 1);
    cvClearHist(hist);

    // Create image(s).
    IplImage* imgRed = cvCreateImage(cvGetSize(img), 8, 1);
    IplImage* imgGreen = cvCreateImage(cvGetSize(img), 8, 1);
    IplImage* imgBlue = cvCreateImage(cvGetSize(img), 8, 1);
    IplImage* imgGrayscale = cvCreateImage(cvGetSize(img), 8, 1);
    IplImage* imgHistEqualized = cvCreateImage(cvGetSize(img), 8, 1);

    // Split image into the color planes.
    cvSplit(img, imgBlue, imgGreen, imgRed, NULL);
    // Convert the image into its corresponding gray-scale image.
	// Add weight to rgb values
    // Y = 0.2126*R + 0.7152*G + 0.0722*B.
	cvAddWeighted( imgRed, 0.2126 , imgGreen, 0.7152 , 0.0, imgGrayscale );
	cvAddWeighted( imgGrayscale, 1.0, imgBlue, 0.0722 , 0.0, imgGrayscale );

	// Compute and draw histogram(s).
    cvClearHist(hist);
    cvCalcHist(&imgGrayscale, hist, 0, 0);
    IplImage* imgHistGrayscale = DrawHistogram(hist);

    // Work on the histogram equalization.
  	cvCopy(imgGrayscale, imgHistEqualized);
    equalizeHistogram(hist, imgHistEqualized);
    //cvEqualizeHist(imgGrayscale, imgHistEqualized);

  	// Compute and draw histogram(s) of the equalized-histogram image.
    cvClearHist(hist);
    cvCalcHist(&imgHistEqualized, hist, 0, 0);
    IplImage* imgHistHistEqualized = DrawHistogram(hist);

    //show window(s).
    cvNamedWindow("Gray scale");
    cvNamedWindow("Gray scale image");
    cvNamedWindow("Histogram equalization");
    cvNamedWindow("Histogram equalization image");

    cvShowImage("Gray scale", imgHistGrayscale);
    cvShowImage("Gray scale image", imgGrayscale);
    cvShowImage("Histogram equalization", imgHistHistEqualized);
    cvShowImage("Histogram equalization image", imgHistEqualized);

    cvWaitKey(0);

    // destroy window(s).
    cvDestroyWindow("Gray scale");
    cvDestroyWindow("Gray scale image");
    cvDestroyWindow("Histogram equalization");
    cvDestroyWindow("Histogram equalization image");

    // release the image
    cvReleaseImage(&imgGrayscale);
    cvReleaseImage(&imgHistGrayscale);
    cvReleaseImage(&imgHistEqualized);
    cvReleaseImage(&imgHistHistEqualized);

    return 0;
}
コード例 #8
0
static void
kms_pointer_detector_init (KmsPointerDetector * pointerdetector)
{
  pointerdetector->cvImage = NULL;
  int h_bins = 30, s_bins = 32;
  int hist_size[] = { h_bins, s_bins };
  float h_ranges[] = { 0, 180 };
  float s_ranges[] = { 0, 255 };
  float *ranges[] = { h_ranges, s_ranges };
  pointerdetector->histModel =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histModel);

  pointerdetector->histCompare =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histCompare);

  pointerdetector->histSetUp1 =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histSetUp1);

  pointerdetector->histSetUp2 =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histSetUp2);

  pointerdetector->histSetUpRef =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histSetUpRef);

  pointerdetector->upCornerFinalRect.x = 20;
  pointerdetector->upCornerFinalRect.y = 10;
  pointerdetector->downCornerFinalRect.x = 40;
  pointerdetector->downCornerFinalRect.y = 30;
  pointerdetector->upCornerRect1.x = 20;
  pointerdetector->upCornerRect1.y = 10;
  pointerdetector->downCornerRect1.x = 40;
  pointerdetector->downCornerRect1.y = 30;
  pointerdetector->upCornerRect2.x = 50;
  pointerdetector->upCornerRect2.y = 10;
  pointerdetector->downCornerRect2.x = 70;
  pointerdetector->downCornerRect2.y = 30;
  pointerdetector->upRightButtonCorner.x = 0;
  pointerdetector->upRightButtonCorner.y = 0;
  pointerdetector->downLeftButtonCorner.x = 0;
  pointerdetector->downLeftButtonCorner.y = 0;
  pointerdetector->windowScaleRef = 5;
  pointerdetector->numOfRegions = 150;
  pointerdetector->windowScale = pointerdetector->windowScaleRef;
  pointerdetector->iteration = 0;
  pointerdetector->state = START;
  pointerdetector->histRefCapturesCounter = 0;
  pointerdetector->secondHistCapturesCounter = 0;
  pointerdetector->trackinRectSize.width =
      abs (pointerdetector->upCornerRect1.x -
      pointerdetector->downCornerRect1.x);
  pointerdetector->trackinRectSize.height =
      abs (pointerdetector->upCornerRect1.y -
      pointerdetector->downCornerRect1.y);
  pointerdetector->colorRect1 = WHITE;
  pointerdetector->colorRect2 = WHITE;
  pointerdetector->show_debug_info = FALSE;
  pointerdetector->buttonsLayout = NULL;
  pointerdetector->buttonsLayoutList = NULL;
  pointerdetector->putMessage = TRUE;
  pointerdetector->show_windows_layout = TRUE;

  gchar d[] = TEMP_PATH;
  gchar *aux = g_mkdtemp (d);

  pointerdetector->images_dir = g_strdup (aux);
}
コード例 #9
0
void process_image(){







///////////////////////////////////////////////////////
//////////////////// PUPIL/////////////////////////////
///////////////////////////////////////////////////////

int numBins = 256;
float range[] = {0, 255};
float *ranges[] = { range };
 
 CvHistogram *hist = cvCreateHist(1, &numBins, CV_HIST_ARRAY, ranges, 1);
 cvClearHist(hist);


	cvCalcHist(&smooth, hist, 0, 0);
    IplImage* imgHist = DrawHistogram(hist,1,1);
    cvClearHist(hist);
	

//cvShowImage("hist", imgHist);



cvThreshold(smooth,pupil,50,255,CV_THRESH_BINARY);
//cvShowImage( "pupi_binary",pupil);

cvCanny(pupil,pedge,40,50);
//cvShowImage( "pupil_edge",pedge);


//////////////////////////////////////////////////////////
//////////////////////IRIS////////////////////////////////
//////////////////////////////////////////////////////////

//cvEqualizeHist(smooth,smooth);
//cvShowImage("Equalized",smooth);

cvThreshold(smooth,iris,100,255,CV_THRESH_BINARY); //115
//cvShowImage( "iris_binary",iris);


//cvSobel(iris,iedge,1,0,3);
cvCanny(iris,iedge,1,255);
//cvShowImage( "iris_edge",iedge);


/////////////////////////////////////////////////////////
///////////////////////Eyelids///////////////////////////
/////////////////////////////////////////////////////////



cvThreshold(smooth,eyelid_mask,150,255,CV_THRESH_OTSU);
cvNot(eyelid_mask,eyelid_mask);
//cvShowImage("eyelid",eyelid_mask);



//cvAdaptiveThreshold(smooth,contour,255,CV_ADAPTIVE_THRESH_MEAN_C,CV_THRESH_BINARY,9,1);

//cvThreshold(smooth,contour,130,255,CV_THRESH_BINARY);
//cvShowImage( "contour",contour);


//CvSeq* firstContour = NULL;
//CvMemStorage* cstorage = cvCreateMemStorage(0);
//cvFindContours(con, cstorage, &firstContour,sizeof(CvContour), CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
//cvDrawContours(dst,firstContour,CV_RGB(0,255,0),CV_RGB(0,0,255),10,2,8);



CvMemStorage* storage_pupil = cvCreateMemStorage(0);

CvSeq* presults = cvHoughCircles(pedge,storage_pupil,CV_HOUGH_GRADIENT,2,src->width,255,1);
for( int i = 0; i < presults->total; i++ )
{
float* p = (float*) cvGetSeqElem( presults, i );
CvPoint pt = cvPoint( cvRound( p[0] ),cvRound( p[1] ) );

xp=cvRound( p[0] );
yp=cvRound( p[1] );
rp=p[2];

cvCircle(dst,pt,cvRound( p[2] ),CV_RGB(0,255,255),1,400);


xroi= xp-shift;
yroi= yp-shift;

cvRectangle(dst,cvPoint(( p[0] )-shift,p[1]-shift),cvPoint(( p[0] )+shift,p[1]+shift),CV_RGB(255,0,255), 1);

CvRect roi= cvRect(xroi  ,yroi,shift*2,shift*2);



cvSetImageROI( iedge, roi );


//cvShowImage("ROI",iedge);


}
////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

CvMemStorage* storage_iris = cvCreateMemStorage(0);

CvSeq* iresults = cvHoughCircles(iedge,storage_iris,CV_HOUGH_GRADIENT,2,src->width,1,50,50);
for( int i = 0; i < iresults->total; i++ )
{
float* p = (float*) cvGetSeqElem( iresults, i );

CvPoint pt = cvPoint( cvRound( p[0] )+xroi,cvRound( p[1] )+yroi );
cvCircle(dst,pt,cvRound( p[2] ),CV_RGB(255,0,0),1,400);


xi=cvRound( p[0] )+xroi;
yi=cvRound( p[1] )+yroi;
ri=(p[2]);


cvCircle(iris_mask,pt,cvRound( p[2] ),CV_RGB(255, 255, 255),-1, 8, 0);
//cvShowImage("iris_mask",iris_mask);


}
///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
///////////////////////////////////////////


cvResetImageROI(iedge);

cvAnd(dst,dst,res,iris_mask);
//cvShowImage("iris_mask",res);

cvAnd(res,res, mask, eyelid_mask);
//cvShowImage("Mask",mask);



//cvLogPolar(mask,finalres,cvPoint2D32f (xp,yp),100, CV_INTER_LINEAR  );
//cvShowImage("Final Result",finalres);


/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/*




*/



}
コード例 #10
0
// ------------------------------------------------------------------------
void LABHistogram2D::Clear() {
	cvClearHist(h);
}
コード例 #11
0
ファイル: main.c プロジェクト: suriyadeepan/cv-workspace
int main(int argc, char* argv[])
{
	IplImage* src = cvLoadImage(argv[1],CV_LOAD_IMAGE_UNCHANGED);

	// get HSV form of image
	IplImage* hsvSrc = cvCreateImage(cvGetSize(src),8,3);
	cvCvtColor(src,hsvSrc,CV_BGR2HSV);

	// initialize Histogram
	int numBins = 256;
    	CvHistogram *hist = cvCreateHist(1,&numBins,CV_HIST_ARRAY,NULL,1);
    	cvClearHist(hist);


	// Separate hsv image into 3 channels
	IplImage* hueCh = cvCreateImage(cvGetSize(hsvSrc),8,1);
	IplImage* satCh = cvCreateImage(cvGetSize(hsvSrc),8,1);
	IplImage* valCh = cvCreateImage(cvGetSize(hsvSrc),8,1);

		cvSplit(hsvSrc,hueCh,satCh,valCh,NULL);


	// **** Rendering Histogram ****

	// --- Hue Channel ---
	cvCalcHist(&hueCh,hist, 0, NULL);
		IplImage* imgHistHue = drawHistogram(hist);
		cvClearHist(hist);

	// --- Sat Channel ---
	cvCalcHist(&satCh, hist, 0, NULL);
	IplImage* imgHistSat = drawHistogram(hist);
		cvClearHist(hist);

	// --- Val Channel ---
	cvCalcHist(&valCh, hist, 0, NULL);
		IplImage* imgHistVal = drawHistogram(hist);
		cvClearHist(hist);

	cvStartWindowThread();

	// display histogram
	cvNamedWindow("Hue",CV_WINDOW_NORMAL);
	cvNamedWindow("Sat",CV_WINDOW_NORMAL);
	cvNamedWindow("Val",CV_WINDOW_NORMAL);

	cvShowImage("Hue",imgHistHue);
	cvShowImage("Sat",imgHistSat);
	cvShowImage("Val",imgHistVal);


	// wait for key press
	cvWaitKey(0);

	// release memory
	cvDestroyAllWindows();
	cvReleaseImage(&src);

	cvReleaseImage(&hueCh);
	cvReleaseImage(&satCh);
	cvReleaseImage(&valCh);

	cvReleaseImage(&imgHistHue);
	cvReleaseImage(&imgHistSat);
	cvReleaseImage(&imgHistVal);

	return 0;
}// end of main