how to use cv::setMouseCallback in a c++ class
Hi !
I'm trying to use the cv::setMouseCallback to crop a frame. it just doesn't work can any body tell the whole program carshes when I use it:
class Mainthread{
......
......'
cv::Mat m_part;
public :
static void mouseHandler(int event,int x,int y, int flags,void* param);
static void draw_box(cv::Mat,cv::Rect);
void gettingROI();
static cv::Rect theBox;
...
void MainThread::gettingROI(){
cv::Mat part m_part = stream.getframe();
name = "roi";
cv::imshow(name,part);
cv::setMouseCallback(name,mouseHandler,&part);
cv::imshow(name,m_part);
cv::setMouseCallback(name,mouseHandler,&m_part);
}
cv::Rect MainThread::theBox = cv::Rect(0,0,0,0);
void MainThread::mouseHandler(int event,int x , int y , int flags, void* param){
cv::Mat* pimage = (cv::Mat*) param;
cv::Mat image = * pimage;
switch( event ){
case CV_EVENT_MOUSEMOVE:
if( drawing_box ){
theBox.width = x-theBox.x;
theBox.height = y-theBox.y;
}.............
..........
the program crashs and After @Vladislav suggestion I don't understand why. thanks for your help changed my code, it work now but I have a problem with cv::Rect theBox any idea