1个回答
展开全部
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <ctype.h>
using namespace cv;
using namespace std;
Mat image;
bool selectObject = false;
bool drawflag=false;
Point origin;
Rect selection(0,0,-1,-1);
void onMouse( int event, int x, int y, int, void* )
{
if( selectObject )
{
selection.width = std::abs(x - origin.x);
selection.height = std::abs(y - origin.y);
drawflag=true;
//selection &= Rect(0, 0, image.cols, image.rows);
}
switch( event )
{
case CV_EVENT_LBUTTONDOWN:
origin = Point(x,y);
selection = Rect(x,y,0,0);
selectObject = true;
break;
case CV_EVENT_LBUTTONUP:
if( selection.width>0 && selection.height>0)
{
selectObject = false;
break;
}
default:
break;
}
}
int main()
{
const char* winname="OnMouseDemo";
VideoCapture cap(0);
namedWindow(winname);
Mat image;
setMouseCallback(winname, onMouse, 0 );
while(1)
{
cap>>image;
if(drawflag)
{
rectangle(image,Point(selection.x,selection.y),Point(selection.x+selection.width ,selection.y+selection.height ),Scalar(255,0,0));
image(selection)=image(selection)+Scalar(0,0,250);
}
imshow(winname,image);
char c = (char)waitKey(10);
if( c == 27 ) break;
if(c=='c') drawflag=false;
}
return 0;
}
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <ctype.h>
using namespace cv;
using namespace std;
Mat image;
bool selectObject = false;
bool drawflag=false;
Point origin;
Rect selection(0,0,-1,-1);
void onMouse( int event, int x, int y, int, void* )
{
if( selectObject )
{
selection.width = std::abs(x - origin.x);
selection.height = std::abs(y - origin.y);
drawflag=true;
//selection &= Rect(0, 0, image.cols, image.rows);
}
switch( event )
{
case CV_EVENT_LBUTTONDOWN:
origin = Point(x,y);
selection = Rect(x,y,0,0);
selectObject = true;
break;
case CV_EVENT_LBUTTONUP:
if( selection.width>0 && selection.height>0)
{
selectObject = false;
break;
}
default:
break;
}
}
int main()
{
const char* winname="OnMouseDemo";
VideoCapture cap(0);
namedWindow(winname);
Mat image;
setMouseCallback(winname, onMouse, 0 );
while(1)
{
cap>>image;
if(drawflag)
{
rectangle(image,Point(selection.x,selection.y),Point(selection.x+selection.width ,selection.y+selection.height ),Scalar(255,0,0));
image(selection)=image(selection)+Scalar(0,0,250);
}
imshow(winname,image);
char c = (char)waitKey(10);
if( c == 27 ) break;
if(c=='c') drawflag=false;
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
博思aippt
2024-07-20 广告
2024-07-20 广告
博思AIPPT是基于ai制作PPT的智能在线工具,它提供了4种AI制作PPT的方式,包括AI生成大纲、AI直接生成PPT、文本生成PPT、AI提炼文档生成PPT,一站式集成多种AI生成PPT的方式,可满足办公用户的不同需求和使用场景。ai生...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询