Results 1 to 6 of 6

Thread: Qt with openCV, cvRealese ERROR

  1. #1
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Qt with openCV, cvRealese ERROR

    Hi all,

    I am getting some problem with my code,

    I can compile and RUN, but it is very laggy.

    My RAM seems not enough for my programme
    If i leave the programme running for a few minutes, it will force close itself without any error msg.

    and, if I quit the programme manually, there is a error messange.

    Below if a part of my code and error msg.
    I think the part have problem is the cvRelease part, and IplImage to QImage part.

    Qt Code:
    1. void Dialog::createCam()
    2. {
    3. timer = new QTimer(this);
    4.  
    5. cam = cvCaptureFromCAM(-1);
    6.  
    7. if(cam==NULL)
    8. qDebug()<<"error";
    9.  
    10. timer->start(0);
    11. connect(timer,SIGNAL(timeout()),this,SLOT(getFrame()));
    12. connect(timer,SIGNAL(timeout()),this,SLOT(prcFrame()));
    13. }
    14.  
    15. void Dialog::getFrame()
    16. {
    17. frame = cvQueryFrame(cam);
    18. QImage image = QImage ((const uchar*)frame->imageData,frame->width,frame->height,QImage::Format_RGB888).rgbSwapped();//rgbSwapped() make color better
    19. ui->original->setPixmap(QPixmap::fromImage(image));
    20. }
    21.  
    22. void Dialog::prcFrame() //threshold,not used yet
    23. {
    24. /*IplImage *imgHSV= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,3);
    25.   cvCvtColor(frame,imgHSV,CV_BGR2HSV);
    26.   IplImage *imgFilter= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1);
    27.   //threshed , get value from slider value*/
    28. cvCloneImage(frame);
    29. cvCvtColor(frame,frame,CV_BGR2HSV);
    30. IplImage *imgFilter= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1);
    31. cvInRangeS(frame,cvScalar(ui->hueSlide1->value(),ui->satSlide1->value(),ui->lumSlide1->value(),0),cvScalar(ui->hueSlide2->value(),ui->satSlide2->value(),ui->lumSlide2->value(),0),imgFilter);
    32.  
    33. QImage imgThresdhed = QImage ((const uchar*)imgFilter->imageData,imgFilter->width,imgFilter->height,QImage::Format_Indexed8).rgbSwapped();
    34. ui->filter->setPixmap(QPixmap::fromImage(imgThresdhed));
    35. }
    36.  
    37.  
    38. Dialog::~Dialog()
    39.  
    40.  
    41. {
    42.  
    43. timer->stop();
    44.  
    45.  
    46. cvReleaseCapture(&cam);
    47.  
    48.  
    49. cvReleaseImage(&imgFilter);
    50.  
    51.  
    52. delete ui;
    53.  
    54.  
    55. }
    To copy to clipboard, switch view to plain text mode 

    ERROR Msg:
    Qt Code:
    1. OpenCV Error: Bad argument (unrecognized or unsupported array type) in cvReleaseData, file /home/pi/OpenCV-2.4.2/modules/core/src/array.cpp, line 996
    2.  
    3.  
    4.  
    5. terminate called after throwing an instance of 'cv::Exception'
    6.  
    7.  
    8.  
    9. what(): /home/pi/OpenCV-2.4.2/modules/core/src/array.cpp:996: error: (-5) unrecognized or unsupported array type in function cvReleaseData
    10.  
    11.  
    12.  
    13.  
    14.  
    15.  
    16. The program has unexpectedly finished.
    17.  
    18.  
    19. /home/pi/qt/getCam/getCam exited with code 0
    To copy to clipboard, switch view to plain text mode 

    PLEASE ADVISE, thank you

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt with openCV, cvRealese ERROR

    1. You are leaking memory by calling cvCloneImage without taking care of releasing the result:
    Qt Code:
    1. cvCloneImage(frame); // bad, leaks memory
    2.  
    3. // should be
    4. IplImage * result = cvCloneFrame(frame);
    5. ...
    6. cvReleaseImage(&result);
    To copy to clipboard, switch view to plain text mode 

    2. You are not allowed to modify the frame returned by cvQueryFrame:
    Qt Code:
    1. cvCvtColor(frame,frame,CV_BGR2HSV); // wrong, attempt to modify frame owned by underlying capture mechanism
    To copy to clipboard, switch view to plain text mode 
    should be
    Qt Code:
    1. IplImage * result = cvCloneFrame(frame);
    2. cvCvtColor(frame,result,CV_BGR2HSV);
    3. // work on the result from now on
    4. cvReleaseImage(&result);
    To copy to clipboard, switch view to plain text mode 
    3. memory leak related to "imgFilter" image not released:
    Qt Code:
    1. IplImage *imgFilter= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1);
    2. // no cvReleaseImage(&imgFilter); after processing this frame
    To copy to clipboard, switch view to plain text mode 
    4. attempt to release uninitialized image in destructor:
    Qt Code:
    1. Dialog::~Dialog()
    2.  
    3.  
    4. {
    5.  
    6. timer->stop();
    7.  
    8.  
    9. cvReleaseCapture(&cam);
    10.  
    11.  
    12. cvReleaseImage(&imgFilter); // this is NOT the image from prcFrame method !
    13.  
    14.  
    15. delete ui;
    16.  
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 
    I assume you don't initialize it in constructor.

  3. The following user says thank you to stampede for this useful post:

    YDYD (9th July 2014)

  4. #3
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt with openCV, cvRealese ERROR

    Hi,
    Thanks for the reply..

    So for *imgFilter and *result, where should i release them?

    Before, i use to do what you tell me,

    i did like this:
    Qt Code:
    1. IplImage *imgHSV= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,3);
    2. cvCvtColor(frame,imgHSV,CV_BGR2HSV);
    3. IplImage *imgFilter= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1);
    To copy to clipboard, switch view to plain text mode 

    but, this show me QImage: no enough memory, return NULL image.

  5. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt with openCV, cvRealese ERROR

    So for *imgFilter and *result, where should i release them?
    When you don't need them anymore, probably at the end of prcFrame method.
    but, this show me QImage: no enough memory, return NULL image.
    That was before or after you've added the image release code ?

  6. The following user says thank you to stampede for this useful post:

    YDYD (9th July 2014)

  7. #5
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt with openCV, cvRealese ERROR

    Hi,

    i added both release at the end and inside of prcFrame method,

    A lot better, but it is still laggy, delay for about 1 sec to 2 sec ,

    anyway, Thanks alot!!

    Have a nice day =)

  8. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt with openCV, cvRealese ERROR

    Hi,

    You are using a 0 time timer and so you don't let too much time to the main thread to process the events.
    You have to calculate the timer resolution using the camera fps. Asign 33ms to the timer to get 30fps and let the proper time to the main thread to update the GUI,...
    Òscar Llarch i Galán

  9. The following user says thank you to ^NyAw^ for this useful post:

    YDYD (10th July 2014)

Similar Threads

  1. Error while working with OpenCV
    By hamykhafan in forum Qt Tools
    Replies: 1
    Last Post: 14th August 2013, 00:42
  2. OpenCV and Qt Error While Running!
    By hazad in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2013, 00:33
  3. Linking Error Qt OpenCV
    By Songi in forum Installation and Deployment
    Replies: 4
    Last Post: 28th August 2011, 05:03
  4. Qt OpenCV SIGSEGV error help
    By bobo in forum Newbie
    Replies: 3
    Last Post: 13th June 2011, 21:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.