Ask Your Question
0

Android: Native Opencv - cvtColor segfault

asked Sep 4 '12

Bia6969 gravatar image

updated Sep 4 '12

Andrey Pavlenko gravatar image

I want to pass a newly taken picture by android camera app to my native part so i can run my object detector over it.

What i've done is, on java code, getting the picture through this: Mat original = Highgui.imread("data");

I've also created two more Mat to pass to the native code as well. I pass the Mat's getNativeObjAddr() and everything works.

The problem is, after i get the arguments (over to the cpp native code) i pass two Mat (original and gray) to cv::InputArray and cv::OutputArray, accordingly, but cvtColor(original(InputArra), gray(OutputArray), CV_BGR2GRAY, 0) gives a segfault and the app closes.

Is this NOT the best way to pass images to native part? Am i doing something wrong? Do you have any suggestion? Please, speak your mind :)

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Sep 4 '12

Andrey Pavlenko gravatar image

Quote your code here, it should be something like this:

Mat& mBgr  = *((Mat*)addrBgr);
Mat& mGray = *((Mat*)addrGray);
cvtColor(mBgr, mGray, CV_BGR2GRAY);

And also don't forget to check that the original Mat isn't empty before the call to cvtColor().

Preview: (hide)

Comments

thanks! i'll try that ;)

Bia6969 gravatar imageBia6969 (Sep 4 '12)edit

As it turns out, original was empty. Now, when i make

Mat ioriginal = Highgui.imread("data");

doesn't it returns a Mat with the newly taken picture data?

Bia6969 gravatar imageBia6969 (Sep 4 '12)edit

As per doc-s

If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix

Andrey Pavlenko gravatar imageAndrey Pavlenko (Sep 4 '12)edit

Well, what i am thinking is that when we use the camera app to take a picture on the emulator, it is not saved so when i try to reach "data", it's not really there. Could it be?

Bia6969 gravatar imageBia6969 (Sep 4 '12)edit

I've been able to work around the empty original problem but, even with the original data the cvtColor func still gives a seg fault. I'll try to convert the longs into cv::InputArray and cv::OutputArray. Am i wrong to so do?

Bia6969 gravatar imageBia6969 (Sep 5 '12)edit
1

As it's stated in doc-s

The "InputArray" class is designed solely for passing parameters. That is, normally you SHOULD NOT declare class members, local and global variables of this type.

Andrey Pavlenko gravatar imageAndrey Pavlenko (Sep 5 '12)edit

Question Tools

Stats

Asked: Sep 4 '12

Seen: 1,806 times

Last updated: Sep 04 '12