Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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{
  ......'
public :
     static void mouseHandler(int event,int x,int y, int flags,void* param);
     void gettingROI();    
...
void MainThread::gettingROI(){
cv::Mat part = stream.getframe();
name = "roi";
cv::imshow(name,part);
cv::setMouseCallback(name,mouseHandler,&part);
  }

the program crashs and I don't understand why. thanks for your help

click to hide/show revision 2
No.2 Revision

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{
  ......'
......
public :
     static void mouseHandler(int event,int x,int y, int flags,void* param);
     void gettingROI();    
...
void MainThread::gettingROI(){
cv::Mat part = stream.getframe();
name = "roi";
cv::imshow(name,part);
cv::setMouseCallback(name,mouseHandler,&part);
  }

the program crashs and I don't understand why. thanks for your help

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

click to hide/show revision 4
No.4 Revision

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(){
m_part = stream.getframe();
name = "roi";
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;
        }.............
..........

After @Vladislav suggestion I changed my code, it work now but I have a problem with cv::Rect theBox any idea