Ask Your Question
0

Android: Native Opencv - cvtColor segfault

asked 2012-09-04 05:47:46 -0500

Bia6969 gravatar image

updated 2012-09-04 09:05:44 -0500

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 :)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-09-04 09:04:16 -0500

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

edit flag offensive delete link more

Comments

thanks! i'll try that ;)

Bia6969 gravatar imageBia6969 ( 2012-09-04 09:12:37 -0500 )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 ( 2012-09-04 09:24:10 -0500 )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 ( 2012-09-04 10:08:45 -0500 )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 ( 2012-09-04 10:14:12 -0500 )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 ( 2012-09-05 05:14:48 -0500 )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 ( 2012-09-05 06:44:04 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-09-04 05:47:46 -0500

Seen: 1,130 times

Last updated: Sep 04 '12