Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
723 views
in Technique[技术] by (71.8m points)

image processing - Error setting ROI OpenCV Android

I am trying to figure out how to set the ROI for an Image in OpenCV on Android. I have done this on other operating systems, so I think HOW I am doing it is semantically correct, but there is an error somewhere.

So far I have tried this

Rect roi = new Rect(0, 0, inputFrame.cols(), inputFrame.rows());
Mat cropped = new Mat(inputFrame, roi);

However I get an error somewhere in the OpenCV classes that looks like this

Utils.matToBitmap() throws an exception:/home/reports/ci/slave/opencv/modules/java/generator/src/cpp/utils.cpp:107: 
error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width ==
(uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2
(JNIEnv*, jclass, jlong, jobject, jboolean)

I am calling this in the onCameraFrame callback provided by opencv wrapper class

Not sure how to go about this, has anyone successfully done this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

OpenCV for Android (and the new Java API) has its own way to create ROI's.

All you have to do is to call the submat method of your Mat object. If I am not mistaken, calling submat does not create a copy of that image region, if you want a copy you can use copyTo on the submat for that purpose.

Mat roi = inputFrame.submat(rowStart, rowEnd, colStart, colEnd);

You can call submat in 3 different ways, check the links for more details:

  • submat(int rowStart, int rowEnd, int colStart, int colEnd)

submat 1

  • submat(Range rowRange, Range colRange)

submat 2

  • submat(Rect roi)

submat 3


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...