opencv 手选roi区域_【OpenCV】选择ROI区域 – 一点心青

1 #include "MouseSelect.h"2 3 MouseSelectParams *g_mousep;4 MouseSelect::MouseSelect() {}5 6 MouseSelect::~MouseSelect() {}7 8 void MouseSelect::select_rect(Mat &frame)9 {10 obj_selected = 0;11 while(0 ==obj_selected)12 {13 obj_selected =get_rects(frame);14 if (obj_selected == 0)15 {16 cout<n;111 if (n ==MAX_OBJECTS)112 {113 return;114 }115 prev_pt.x =x;116 prev_pt.y =y;117 //cout<mode)125 {126 n = g_mousep->n;127 if (n ==MAX_OBJECTS)128 {129 return;130 }131 cur_pt.x =x;132 cur_pt.y =y;133 g_mousep->pts.push_back(cur_pt);134 int radius = 3;135 circle(*g_mousep->image,cur_pt,radius,CV_RGB(255,0,0));136 imshow(g_mousep->win_name,*g_mousep->image);137 pressed = false;138 g_mousep->n++;139 }140 /*2 == mode for selecting rectangles*/141 else if (2 == g_mousep->mode)142 {143 n = g_mousep->n;144 if (n ==MAX_OBJECTS)145 {146 return;147 }148 cur_pt.x =x;149 cur_pt.y =y;150 g_mousep->pts.push_back(prev_pt);151 g_mousep->pts.push_back(cur_pt);152 //cout<image,prev_pt,cur_pt,CV_RGB(0,0,255));154 imshow(g_mousep->win_name,*g_mousep->image);155 pressed = false;156 g_mousep->n++;157 }158 else if (3 == g_mousep->mode)159 {160 n = g_mousep->n;161 162 }163 }164 else if (event == CV_EVENT_MOUSEMOVE && pressed &&CV_EVENT_FLAG_LBUTTON)165 {166 if (2 == g_mousep->mode)167 {168 n = g_mousep->n;169 if (n ==MAX_OBJECTS)170 {171 return;172 }173 cur_pt.x =x;174 cur_pt.y =y;175 Mat tmp = (*g_mousep->image).clone();176 //cout<win_name,tmp);179 }180 }181 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值