问题描述
我试图找出如何设置投资回报率在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);
不过我看起来像这样OpenCV的类的地方得到一个错误
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)
我通过OpenCV的包装类提供的onCameraFrame回调调用这个
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?
推荐答案
OpenCV的为Android(和新的Java API)有自己的方式创造的投资回报率。
OpenCV for Android (and the new Java API) has its own way to create ROI's.
所有你所要做的就是打电话给你垫目标的submat方法。如果我没有记错的话,叫submat不会创建图像区域的副本,如果你想要一个副本,你可以在submat为目的的使用将copyTo。
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);
您可以拨打submat在3个不同的方式,检查的链接了解详情:
You can call submat in 3 different ways, check the links for more details:
- submat(INT rowStart,诠释rowEnd,诠释colStart,INT colEnd)
submat 1
- submat(范围rowRange,范围colRange)
submat 2
- submat(矩形ROI)
这篇关于错误设置ROI的OpenCV的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!