+++ /dev/null
-/************************************************************************************\r
-*\r
-*\r
-* This program is demonstration for histogram and functions: cvCreateHist(), \r
-* cvSetHistThresh(), cvCalcHist(), cvNormalizeHist(), cvQueryHistValue_1D(),\r
-* cvReleaseHist() and cvCopyHist().\r
-*\r
-*\r
-* Trackbar specify normalize factor for histogram value.\r
-*\r
-*\r
-*\r
-* Autor: Denis Burenkov\r
-*\r
-*\r
-************************************************************************************/\r
-\r
-#define DIMENSION_SIZE 50\r
-\r
-char file_name[] = "EXPO0002.bmp";\r
-\r
-char wndname01[] = "Source image";\r
-char wndname02[] = "Histogram";\r
-char barname01[] = "Normalize factor";\r
-int dims[1] = {DIMENSION_SIZE};\r
-float thresh[1][2] = { {0, 255} };\r
-float* pthresh[1] = { thresh[0] };\r
-int slider_pos[1] = {2000};\r
-\r
-// Load the source image. HighGUI use.\r
-IPLIMAGE image01 = load_iplimage( file_name );\r
-\r
-if(image01==NULL)\r
-{\r
- printf("File '%s' not found.\n", file_name);\r
- \r
-}\r
-\r
-// Create the destination images. HighGUI use.\r
-IplImage * image02 = cvCreateImage( cvSize(image01->width,image01->height),\r
- IPL_DEPTH_8U,\r
- 1);\r
-IplImage * image03 = cvCreateImage( cvSize(image01->width,image01->height),\r
- IPL_DEPTH_8U,\r
- 3);\r
- \r
-// Make onechannel image.\r
-cvCvtColor(image01,image02, CV_BGR2GRAY);\r
-\r
-\r
-// Created histogram headers. OpenCV use.\r
-CvHistogram* hist01 = cvCreateHist(1, // Histogram dimension number.\r
- dims, // Dimension size array.\r
- CV_HIST_ARRAY, // Histogram type.\r
- 0, 1); \r
- \r
-CvHistogram* hist02 = cvCreateHist(1, dims, CV_HIST_ARRAY, 0, 1);\r
-\r
-\r
-// Set bounds of histogram bins. The histogram or back project are calculated \r
-// if within the specified boundaries. \r
-// OpenCV use.\r
-cvSetHistBinRanges( hist01, // Destination histogram.\r
- pthresh, 1); // Pointer to the array of threshold values.\r
-\r
-\r
-\r
-// Create windows. HighGUI use.\r
-named_window( wndname01, 0 );\r
-named_window( wndname02, 0 );\r
-\r
-// Show the image. HighGUI use.\r
-show_iplimage( wndname01, image02 );\r
-\r
-\r
-// Calculated the histogram. OpenCV use. \r
-cvCalcHist( &image02, // Source images.\r
- hist01, // Pointer to the histogram.\r
- 0, 0 ); // Clear flag.\r
-\r
-\r
-// Define trackbar callback functon. This function normalize and draw histogram.\r
-void ShowHist(int h)\r
-{\r
- int i;\r
- CvPoint pt1, pt2;\r
- pt2.x=0;\r
- pt2.y=image01->height;\r
- \r
- // Clear image. OpenCV use.\r
- //cvFillImage(image03,0); //old code\r
- cvSetZero(image03);\r
- \r
- \r
- // Copy histogram to save data. OpenCV use.\r
- cvCopyHist(hist01, // Source histogram.\r
- &hist02); // Pointer to destination histogram.\r
- \r
- // Normalize histogram.\r
- // The sum of histogram bins becomes equal to factor.\r
- // OpenCV use.\r
- cvNormalizeHist( hist02, //Pointer to the histogram.\r
- slider_pos[0] ); //Normalize factor.\r
- \r
- // Draw histogram.\r
- for(i=0; i<DIMENSION_SIZE; i++)\r
- {\r
- pt1.x=pt1.x+5;\r
- pt1.y=image01->height -\r
- cvQueryHistValue_1D(hist02, // Pointer to the source histogram.\r
- i); // Address of a required element.\r
- // The function cvQueryHistValue_1D() returns the\r
- // value of the specified histogram bin.\r
- \r
- pt2.x=pt2.x+5;\r
- \r
- cvLine(image03, pt1, pt2, CV_RGB(200,0,0), 2, 8);\r
- }\r
- \r
- // Show the image. HighGUI use.\r
- show_iplimage( wndname02, image03 );\r
-}\r
-\r
-\r
-\r
-ShowHist(0);\r
-\r
-// Create toolbars. HighGUI use.\r
-create_trackbar(barname01, \r
- wndname02,\r
- &slider_pos[0],\r
- 4000,\r
- ShowHist);\r
-\r
-// Wait for a key stroke; the same function arranges events processing \r
-wait_key(0);\r
-cvReleaseImage(&image01);\r
-cvReleaseImage(&image02);\r
-cvReleaseImage(&image03);\r
-\r
-destroy_window(wndname01);\r
-destroy_window(wndname02);\r
-\r
-cvReleaseHist( &hist01 );\r
-cvReleaseHist( &hist02 );\r
-\r
-// END
\ No newline at end of file