2

I have a rotatedRect that I find on my image, and I want to retrieve the subMatrice of all pixel in this rotatedRect. I find this C++ code on this topic : http://answers.opencv.org/question/497/extract-a-rotatedrect-area/ and here my Java code:

   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

And here my error in the 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)

It seems that getRectSubPix function doesn't work in Java, someone found a solution?

1
  • Have you found the solution to this? Im getting this error also Mar 14, 2017 at 10:40

1 Answer 1

1

I had a similar error on python using cv2.getRectSubPix:

    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

I resolved it by converting my image from 8bit grayscale to 32bit floating point.

1
  • Hi how to convert image from 8bit grayscale to 32bit floating point. can you please help me. Apr 8, 2015 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.