Ask Your Question

how to detect corners in frames retrieved from Camera

asked 2016-10-20 05:42:47 -0500

AMEMB gravatar image

updated 2016-10-20 05:47:17 -0500

I am working with OpenCV4Android version 2.4.11, and I am trying to detect cornrs in frames retrieved from the camera. i used "cornerHarris" method to detect the corners as shown in the code below. the problem is, at run time the Mat object that is named "corner" is completely black.

please let me know why the Mat that contains the corners is balck and how to solve this problem


Mat mMatGray = new Mat();
Imgproc.cvtColor(mMatInputFrame, mMatGray, Imgproc.COLOR_BGR2GRAY);

corners = new Mat(mMatInputFrame.size(), CvType.CV_32FC1, Scalar.all(0));

corners.convertTo(corners, CV_8UC(4) );

final Bitmap bitmap = Bitmap.createBitmap(mMatInputFrame.cols(), mMatInputFrame.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(corners, bitmap);
getActivity().runOnUiThread(new Runnable() {
    public void run() {
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-10-20 07:23:02 -0500

berak gravatar image

updated 2016-10-20 08:30:08 -0500

first, please have a look at the harris_detector tutorial

you will see, that the output is a Mat with [0..1] float probabilites, your attempt at converting it to a visible image has 2 flaws:

  • if you convert from float to uchar, it will round any float value between 0 and 1 to either 0 or 1. you loose precision, and a value of 1 is still almost black (invisible), so you need a scale factor there:

    corners.convertTo(corners, CV_8U, 255 );

  • then, convertTo() only changes the depth of your pixel type, not the number of channels ! (so your CV_8UC4 does not anything else than CV_8U). for this, you would need another :

    Imgproc.cvtColor(corners, corners, Imgproc.COLOR_GRAY2BGRA);

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-10-20 05:42:47 -0500

Seen: 585 times

Last updated: Oct 20 '16