java - Imgproc.getRectSubPix OpenCV 函数在 Java 中给出错误

标签 java android opencv image-processing

我在图像上找到了一个 rotatedRect,我想检索这个 rotatedRect 中所有像素的子矩阵。我在这个主题上找到了这个 C++ 代码:http://answers.opencv.org/question/497/extract-a-rotatedrect-area/这是我的 Java 代码:

   Mat M = new Mat(), rotated = new Mat(), cropped = new Mat();

    // get angle and size from the bounding box
    double angle = mTable.angle;
    Size rect_size = mTable.size;

    if (mTable.angle < -45.0) {
        angle += 90.0;
        double w = rect_size.width;
        rect_size.width = rect_size.height;
        rect_size.height = w;
    }

    // get the rotation matrix
    M = Imgproc.getRotationMatrix2D(mTable.center, angle, 1.0);

    // perform the affine transformation
    Imgproc.warpAffine(mRgba, rotated, M, mRgba.size(), Imgproc.INTER_CUBIC);

    // crop the resulting image
    Imgproc.getRectSubPix(rotated, rect_size, mTable.center, cropped); //THIS LINE DOESN'T WORK

这是我在 logCat 中的错误

02-17 17:02:34.791: E/cv::error()(3588): OpenCV Error: Unsupported format or combination of formats () in void cvGetRectSubPix(void const*, void*, CvPoint2D32f), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/samplers.cpp, line 556
02-17 17:02:34.791: E/org.opencv.imgproc(3588): imgproc::getRectSubPix_11() caught cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/samplers.cpp:556: error: (-210)  in function void cvGetRectSubPix(void const*, void*, CvPoint2D32f)
02-17 17:02:34.791: W/dalvikvm(3588): threadid=11: thread exiting with uncaught exception (group=0x418ccda0)
02-17 17:02:34.791: E/AndroidRuntime(3588): FATAL EXCEPTION: Thread-29491
02-17 17:02:34.791: E/AndroidRuntime(3588): Process: com.example.testopencv, PID: 3588
02-17 17:02:34.791: E/AndroidRuntime(3588): CvException [org.opencv.core.CvException: cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/samplers.cpp:556: error: (-210)  in function void cvGetRectSubPix(void const*, void*, CvPoint2D32f)
02-17 17:02:34.791: E/AndroidRuntime(3588): ]
02-17 17:02:34.791: E/AndroidRuntime(3588):     at org.opencv.imgproc.Imgproc.getRectSubPix_1(Native Method)
02-17 17:02:34.791: E/AndroidRuntime(3588):     at org.opencv.imgproc.Imgproc.getRectSubPix(Imgproc.java:6618)
02-17 17:02:34.791: E/AndroidRuntime(3588):     at com.example.testopencv.MainActivity.continueTrackingRedBall(MainActivity.java:336)
02-17 17:02:34.791: E/AndroidRuntime(3588):     at com.example.testopencv.MainActivity.onCameraFrame(MainActivity.java:155)
02-17 17:02:34.791: E/AndroidRuntime(3588):     at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)
02-17 17:02:34.791: E/AndroidRuntime(3588):     at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:328)
02-17 17:02:34.791: E/AndroidRuntime(3588):     at java.lang.Thread.run(Thread.java:841)

getRectSubPix 函数似乎在 Java 中不起作用,有人找到了解决方案吗?

最佳答案

我在使用 cv2.getRectSubPix 的 python 上遇到了类似的错误:

    img_cropped = cv2.getRectSubPix(img_rotated, size_xy, center_xy)
cv2.error: /tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20141231-1923/modules/imgproc/src/samplers.cpp:591: error: (-210)  in function cvGetRectSubPix

我通过将我的图像从 8 位灰度转换为 32 位浮点来解决它。

关于java - Imgproc.getRectSubPix OpenCV 函数在 Java 中给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28565778/

相关文章:

java - 在java中下载文件时出错-java.net.SocketException : Connection reset

java - 如何使用 for 循环创建一个正方形

java - 将请求转发到 Spring MVC 中的另一个 Controller

java - Android 6.0 发布时应用程序崩溃,包括 Logcat,新开发人员

java - 我已经构建了一个 WebView 应用程序,但网站下的弹出窗口未显示

android - 我们可以在aidl中声明一个原始类型的变量吗

android - 如何在 Android 应用程序中验证 SSL 证书的有效性

python - OpenCV Python 中的等效 im2double 函数

python - 比较两个图像-python,openCV

c++ - iOS 上的 OpenCv 2.4.7 错误 background_segm.hpp #include <list> not found