欢迎你客人 ( 登录 | 注册 )

  评价 XXXX

entry 2008-12-21, 16:47 PM
始终不能在窗口上显示该像素的颜色值,
无奈的很。
代码
#include "cv.h"
#include "highgui.h"
#include "stdio.h"

// Define our callback which we will install for
// mouse events.
//
void my_mouse_callback(
         int event, int x, int y, int flags, void* param
         );
bool showingRGB=false;
CvPoint pt;
char* mytext;

void showRGB(IplImage* img, CvPoint pt);



int main( int argc, char** argv ) {


IplImage *frame=NULL;
cvNamedWindow("Video",1);
// cvNamedWindow("Video1",1);

frame=cvLoadImage("D:\\Program Files\\OpenCV\\_make\\test\\Debug\\a.jpg");

IplImage* temp = NULL;//cvCloneImage( frame);

cvSetMouseCallback(
  "Video",
  my_mouse_callback,
  (void*) frame
  );


while( 1 ) {
//  cvCopyImage( frame, temp );
  if(showingRGB) showRGB(frame,pt);
  cvShowImage( "Video", frame );
// cvShowImage( "Video1", frame );
  if( cvWaitKey( 15 )==27 ) break;
}



cvReleaseImage(&frame);
cvReleaseImage(&temp);

cvDestroyAllWindows();
return 0;
}

void my_mouse_callback(
         int event, int x, int y, int flags, void* param )
{
IplImage* img = (IplImage*) param;

switch( event ) {
case CV_EVENT_LBUTTONDOWN: {
   showingRGB=false;
  pt=cvPoint(x,y);
// pt.x=x;
// pt.y=y;
  showingRGB=true;
  cvWaitKey(50);

break;
       }
case CV_EVENT_LBUTTONUP:{
  showingRGB=false;
  break;
    }
case CV_EVENT_MOUSEMOVE: {
  showingRGB = false;
     }
  break;
}

}
void showRGB(IplImage* img, CvPoint pt)
{

//用来显示文字,初始化字体
CvFont font=cvFont(1);
// cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX,1, 1);


  CvScalar s;
  s=cvGet2D(img,pt.x,pt.y); // get the (x,y) pixel value
printf("%d ",int(s.val[0]));
// unsigned char R = CV_IMAGE_ELEM(img, unsigned char, pt.x, pt.y*3 + 2);
//itoa(int(s.val[0]),mytext,10);
//cvPutText(img,mytext,cvPoint(pt.x,pt.y),&font,cvScalar(0));
  itoa(pt.x,mytext,10);
cvPutText(img,mytext,pt,&font,cvScalar(0));
itoa(pt.y,mytext,10);
cvPutText(img,mytext,cvPoint(pt.x+30,pt.y),&font,cvScalar(0));
}



  Fast Reply Reply to this topic

« 前一篇文章 · 弱者道之用 · 后一篇文章 »
 
☜εїз:❉:εїз☞
Ari的Q群:17884905

Visual C++图像群:2122649




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31



搜索我的 Blog


0 正在查看的用户
0 游客
0 会员
0 匿名会员

About Here
有事点这里

我的 Blog 链接

随机图片
tn_gallery_133349_2913_23717.jpg