Constantly cv::Exception from cvtcolor() when running code with GDB

asked 2014-06-25 14:26:41 -0600

hudac gravatar image

updated 2014-06-25 14:39:51 -0600

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:

gdb

alt text

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.

edit retag flag offensive close merge delete

Comments

1

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)

berak gravatar imageberak ( 2014-06-25 14:30:49 -0600 )edit

What do you mean? I do: capture.read(cameraFeed); while cameraFeed is Mat. Then I call cvtColor(cameraFeed, HSV, COLOR_BGR2HSV); (Mat HSV)

hudac gravatar imagehudac ( 2014-06-25 14:36:51 -0600 )edit

so, probably your capture was not valid. did you check it ? (capture.isOpened())

berak gravatar imageberak ( 2014-06-25 14:45:13 -0600 )edit

I will check it. But why doesn't the exception being thrown when I don't run it with gdb?

hudac gravatar imagehudac ( 2014-06-25 14:45:30 -0600 )edit

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"); }

hudac gravatar imagehudac ( 2014-06-25 14:47:43 -0600 )edit

btw, what do you need all those threads for ? you do proper locking ? that's not for the faint of heart ...

berak gravatar imageberak ( 2014-06-25 14:47:56 -0600 )edit

ok, if (!capture.open()) is the same check, so that's ok.

berak gravatar imageberak ( 2014-06-25 14:50:45 -0600 )edit

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..

hudac gravatar imagehudac ( 2014-06-25 16:19:21 -0600 )edit

Thanks @berak, the problem was that the first read was empty(). so mat.empty() solved it!

hudac gravatar imagehudac ( 2014-06-27 06:05:34 -0600 )edit
1

ahh, ok. indeed, some camera need a 'warmup time' and deliver empty frame(s) on startup

berak gravatar imageberak ( 2014-06-27 06:09:16 -0600 )edit