Constantly cv::Exception from cvtcolor() when running code with GDB
Hey,
I'm running opencv 2.4.9
on ubuntu 13.10
.
The code (c++
) which calls the opencv
functions is in a different thread.
After compiling the code, if I start it from console it works and everything is fine.
If I try to start the code with GDB I always get the following exception:
I tried to compile opencv
with DEBUG
flag and it didn't help.
edit 1: piece of code:
Mat cameraFeed;
Mat HSV;
capture.read(cameraFeed);
cvtColor(cameraFeed, HSV, COLOR_BGR2HSV);
Does anyone know anything about it?
Please tell if you need further information.
let me guess: you were trying to use cvtColor, and the input was invalid. you should check the input Mat : if ( mat.empty() ) ...
(probably, looking at your code would help)
What do you mean? I do:
capture.read(cameraFeed);
whilecameraFeed
isMat
. Then I callcvtColor(cameraFeed, HSV, COLOR_BGR2HSV);
(Mat HSV
)so, probably your capture was not valid. did you check it ? (capture.isOpened())
I will check it. But why doesn't the exception being thrown when I don't run it with gdb?
I don't use
capture.isOpened()
, but I use:if (!capture.open(-1)) //Use -1 in order to get the default camera { throw new string("Couldn't open camera"); }
btw, what do you need all those threads for ? you do proper locking ? that's not for the faint of heart ...
ok, if (!capture.open()) is the same check, so that's ok.
Well, it's actually a robot, so there is one thread for the vision (opencv), one thread for the motion etc... That's why I need all those threads..
Thanks @berak, the problem was that the first read was empty(). so mat.empty() solved it!
ahh, ok. indeed, some camera need a 'warmup time' and deliver empty frame(s) on startup