【问题标题】:How can i draw lines on a image using mouse in opencv and c++?如何在 opencv 和 c++ 中使用鼠标在图像上画线?
【发布时间】:2014-10-21 16:17:03
【问题描述】:

我的目标是在 opencv 和 c++ 中使用鼠标在图像中画一条线。我在网上查看了不同的代码,但我想在脑海中有一些想法后自己尝试一些东西。我可能完全错了,但我只是一个初学者。所以,我想尝试但它仍然无法正常工作,所以我想在这里发布它。如果可能,请纠正我的错误。

 POINT p;
  GetCursorPos(&p);
 bool drawing;
  int x;
  int y;
  int startx,starty;
  int finishx,finishy;

  int z;
  int l;
Mat a;
a = imread("a.JPG");

 if(GetKeyState(VK_LBUTTON) & 0x80 != 0)
 {
     drawing = true;
     x = p.x;
    y = p.y;
    startx = x;//the starting position to start the drawing
     starty = y;


 }
if(GetKeyState(VK_RBUTTON) &0x80 != 0)
 {
     drawing = false;
    z= p.x;
    l = p.y;

    finishx = z;
    finishy = l;

 }
if(drawing==true)
  {
      line(a,Point(startx,starty),Point(finishx,finishy),Scalar(0,0,255),1);
          imshow("test image",a);
  }

【问题讨论】:

    标签: c++ opencv image-processing


    【解决方案1】:

    你需要把你的画线代码放在setMouseCallback()指定的回调函数中。 OpenCV 有一个demo of how to do the callback。另请参阅此问题的答案Drawing rectangle or line using mouse events in open cv using python(答案在 C++ 中)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-09
      • 2015-04-15
      • 1970-01-01
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      相关资源
      最近更新 更多