openv中基于MouseEvent的绘图
Drawing based on MouseEvent in opencv
我试图根据鼠标事件在帧上画一个矩形,问题是当我得到视频时我不能这样做,程序崩溃了这是我的代码:
cv::Rect theBox;
bool drawing_box = false;
void draw_box(Mat* frame, cv::Rect rectangle){
cvRectangle( frame, cvPoint(theBox.x, theBox.y), cvPoint heBox.x+theBox.width,theBox.y+theBox.height),
cvScalar(0xff,0x00,0x00) );
}无效鼠标(int event, int x, int y,int flags, Void * parameter){
Mat* image = (Mat*) parameter;
switch( event ){
case CV_EVENT_MOUSEMOVE:
if( drawing_box ){
theBox.width = x-theBox.x;
theBox.height = y-theBox.y;
}
break;
case CV_EVENT_LBUTTONDOWN:
drawing_box = true;
theBox = cvRect( x, y, 0, 0 );
break;
case CV_EVENT_LBUTTONUP:
drawing_box = false;
if( theBox.width < 0 ){
theBox.x += theBox.width;
theBox.width *= -1;
}
if( theBox.height < 0 ){
theBox.y += theBox.height;
theBox.height *= -1;
}
draw_box( image, theBox );
//cv::rectangle(parameter, theBox, CV_RGB(255,0,0));
break;
}
}
int main(){
cv::Mat frame;
int key = 0 ;
const char* name = "box";
theBox = Rect(-1,-1,0,0);
cv::VideoCapture cap(1);
if (!cap.isOpened()){
cout<< " capture isn't open " << endl;
return -1;
}
cv::namedWindow(name);
while (key != 27){
cap >> frame;
cv::imshow(name,frame);
cv::setMouseCallback(name,mouse,&frame);
key = cv::waitKey(1);
}
cv::destroyAllWindows();
return 0;
}
当视频流正在发生时,显示正在更新…同时,试图画一个矩形是困难的……由于矩形是根据鼠标移动的输入来绘制的,而鼠标移动是独立于流视频帧的…因此矩形可能会被覆盖(但不应该崩溃)。你可以尝试在视频帧显示的每次迭代中在视频帧上绘制一个透明的(大小取决于鼠标移动事件…)屏幕…
相关文章:
- GTKMM:拍摄绘图区域的屏幕截图?
- GTKMM:如何将键盘事件附加到绘图区域?
- QT 事件过滤器 mouseEvent->pos().x() 始终为零,但 mouseEvent->pos().y() 工作正常
- OpenGL:使用实例化绘图与我正在绘制的帧缓冲进行绘制
- 为什么在我释放左键单击后,我的绘图会消失
- 如何防止opengl绘图拉伸到窗口大小?
- QT 无法通过上下文菜单添加新绘图 (QCustomPlot)
- Wxwidgets - 如何添加调整大小事件处理程序以使"X"绘图随窗口调整大小?
- oFx:使用 mouseEvent 初始化类实例
- 单击"推送"按钮应使用Qt C++在不同的窗口中显示绘图
- 从 C++ 调用 GNU 绘图,无需用户输入
- 播放视频时在 qwidget 上绘图
- 在 qt 中的绘图中拖动误差线
- 在作为表后面图层的标签上绘图
- WinAPI - 获取用于绘图的可滚动框架
- 使用C Visual Studio创建一个绘图图
- 定期使用 QPainter 绘图
- 在 DIB 上绘图不起作用
- 在 Direct2D 绘图中,调整窗口大小后尺寸会更改
- openv中基于MouseEvent的绘图