Solved Issue with threading and opencv
-
@Kira said in Issue with threading and opencv:
QueuedConnection
forces a copy of the arguments, The MetaSystem doesn't know the type cv::Mat -> can't be transmitted via QueuedConnection.
Check your console output you should have warning of unknown metatyps (declare and/or register)
-
@J.Hilk : I have registered it.
#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{
qRegisterMetaType< cv::Mat >("cv::Mat");
QApplication a(argc, argv);
MainWindow w;
w.show();return a.exec();
}
-
the data goes most likely out of scope, as the copy constructor of cv::Mat does actually no coping
I had the same issues in my time with opencv.
ended up converting it to a Image before transferring it from the opencv thread to the normal one.
-
@J.Hilk : Just for clarification should i replace this part with cv::clone
void saveImage(Mat finalImage,String row, String column); -
@J-Hilk : will try and also i tried to run the program in debug mode and getting the following error.
Debugger redirects to following line of file of ostream:
// MANIPULATORS
template<class _Elem,
class _Traits> inline
basic_ostream<_Elem, _Traits>&
__CLRCALL_OR_CDECL endl(basic_ostream<_Elem, _Traits>& _Ostr)
{ // insert newline and flush stream
_Ostr.put(_Ostr.widen('\n'));
_Ostr.flush();
return (_Ostr);
}And the program quits.
Can u please explain what may be the relevant reason for error -
@Kira Please post the stack trace after crash
-
@jsulm : I thought this is the stack trace after crash
-
-
@jsulm : This is the only thing which i see after crash with exception triggered.
Is there any other way to do so -
@Kira In QtCreator if you start with debugger you will have a stack trace
-
@jsulm : Are you referring to this:
Please let me know in case of any issues -
@Kira Yes. Now you need to go from top to bottom until you hit first source code file from your project and check it at the line mentioned in the stack trace.
-
@jsulm : I tried doing it but the error is expected to come after thread running >150 times which is making the debugging process very difficult.
I have also sample test case on github can you please go through it for any possible issues.
https://github.com/HackersSpirit/ImageProcessor -
@Kira said in Issue with threading and opencv:
150 times
you can tell a breakpoint to be ignored for a certain amount of time
-
@Kira I actually suggested to go through the stack trace after crash from top to bottom. No break points needed for that.
-
@jsulm :
@Kira said in Issue with threading and opencv:@jsulm : Are you referring to this:
Please let me know in case of any issuesThis is the stack trace which i get posted earlier referring from line no 1. It does not point to line of code where program has a break.
But line 16 and 17 point to the line of the code.
Should i refer those line for particular cause of the program to break
Please do let me know if i getting something wrong -
@Kira Check your code in that source code at line 16 and 17.
-
@jsulm :
Line 16 is pointing to following line in bold:
void ImageMapping::requestReWorkNew()
{
cout<<"Inside requestRework Newwwwwwwwww"<<endl;
const int sleep = 50;
int queueSize = queueImageName.size();
cout<<"Queue size Request Rework New: "<<queueSize<<endl;
if(queueImageName.size()!=0){
//Get the current image number from the list of images
mutex.lock();
_working = true;
_abort = false;
mutex.unlock();
cout<<"Emiting resume work"<<endl;
emit resumeWork();
}else{
cout<<"Signalling retrying"<<endl;emit retrying(); }
}
This function is basically a slot triggered by following signal:
connect(imageMapping, SIGNAL(finished()), imageMapping, SLOT(requestReWorkNew()));
connect(imageMapping, SIGNAL(retrying()),imageMapping,SLOT(requestReWorkNew())); -
@Kira Are you sure this is the line? The actual line is mentioned in the "Line" column in the stack trace. So, it would be 2129.
-
@Kira you can double click on the line (in QtCreator) of the stack trace and it will open the file at the correct line