App Crashes when I try to get RGB values from cv::Mat
I I am trying to get the R,G & B values of a pixel in a cv::Mat. Here is the method to get the value of B:
int blue = img.at<cv::vec3b>(row,col)[0];
The app Crashes without any error log with EXC_BAD_Excess on the this statement.
I also tried the following method but ran into same problem:(
uchar b = frame.data[frame.channels()frame.colsy + x + 0];
I have successfully added the opencv2.framework in my project. I have added the compiler flags to compile for objective-C++and the normal conversions from cv::Mat to UIImage and vice versa are working fine.
Can any one please help me figure out the reason for this crash??
Am I not allowed to use the "Mat::at(int i0, int i1)" method in Objective-C for iOS?
OR is there any alternative method to get the R,G & B values from a cv::Mat?
Can you check which value img.type() returns?
@Moster: Thanks for the response. I just tried the img.type() and come to know a different thing. Actually here is what I am attempting: Saving 30 frames(cv::Mat) from the video using the delegate method of CvVideoCamera. Then trying to apply an algorithm on RGB values of each frame.
Now when I tried img.type() I came to know that it is not crashing for the first frame. It works fine for the first 24 frames, giving me img.type() = 24 in the console, and then for the 25th frame, it prints img.type() = 0. This is where its crashing.
Ok. type 24 leads to the fact that you even have 4 channels and not just 3. So in this case you could use cv::vec4b, although it wont make a difference regarding the crash. What I find kind of strange is that to the end you get a 1 channel uchar image. So you would need to use image.at<uchar>(x,y). You could check of which type your image is before accessing the pixels.