#include <highgui.h> #include <cv.h> #include draw = ; IplImage* IplImage * IplImage * draw_hist = IplImage* getHistImage(IplImage* image, CvHistogram* cvCalcHist( &image, image_hist, IplImage* dst = cvCreateImage(image_size, IPL_DEPTH_8U, cvSet( dst, cvScalarAll( max_value = cvGetMinMaxHistValue( image_hist, NULL, & bin_width = ()dst->width/ bin_unith = ()dst->height/max_value; ( i = ; i < ; i++ CvPoint p0 = cvPoint( i + bin_width, dst-> CvPoint p1 = cvPoint( (i+) * dst->height - cvGetReal1D(image_hist->bins, i) * cvRectangle( dst, p0, p1, value, -, , draw_rect(IplImage* cvPoint( rect.x + rect.width, rect.y + cvScalar( , , printf( IplImage* src_rect = img->depth, img-> IplImage* r_img = src_rect->depth, IplImage* g_img = src_rect->depth, IplImage* b_img = src_rect->depth, IplImage* gray_img = src_rect->depth, cvShowImage( cvShowImage( cvShowImage( size = range[] = {, * ranges[] = CvHistogram * r_hist = cvCreateHist( , &size, CV_HIST_ARRAY, ranges, CvHistogram * g_hist = cvCreateHist( , &size, CV_HIST_ARRAY, ranges, CvHistogram * b_hist = cvCreateHist( , &size, CV_HIST_ARRAY, ranges, CvHistogram * gray_hist = cvCreateHist( , &size, CV_HIST_ARRAY, ranges, CvSize image_size = cvSize( , IplImage* r_dst = getHistImage(r_img, r_hist, image_size, cvScalar(, , IplImage* g_dst = getHistImage(g_img, g_hist, image_size, cvScalar(, , IplImage* b_dst = getHistImage(b_img, b_hist, image_size, cvScalar(, , IplImage* gray_dst = getHistImage( gray_img, gray_hist, image_size, cvScalar( IplImage* dst = cvCreateImage( cvSize( image_size.width * , image_size.height * ), , CvRect r_rect = cvRect( , CvRect g_rect = cvRect(image_size.width, CvRect b_rect = cvRect( CvRect gray_rect = cvShowImage( cvShowImage( cvWaitKey( cvReleaseImage( & cvReleaseImage(& cvReleaseImage(& cvReleaseImage(& cvReleaseImage(& cvReleaseImage(& cvReleaseImage(& cvReleaseImage(& cvReleaseImage(& cvReleaseImage(& my_mouse_callback( , x, y, flags, * IplImage* image = (IplImage* ( rect.width = x - rect.height = y - draw_hist = draw = rect = cvRect( x, y, , draw_hist = draw = draw_hist = (rect.width < rect.x += rect.width *= - (rect.height < rect.y += rect.height *= - printf( img = cvLoadImage( , rect = cvRect( -, -, , temp = original = cvNamedWindow( cvSetMouseCallback(, my_mouse_callback, (* ( cvShowImage( (cvWaitKey() == cvReleaseImage(& cvReleaseImage(& }
運行結果:
不足:在源圖像上用鼠標選擇矩形區域的時候,無法實時地在圖像上反映出來。