0

I'm trying to track a laser dot using OpenCV on an Android device. I want to use this laserdot to draw on a canvas which is placed upon my cameraview.

I've converted my camerapreview to HSV color space and used threshold filtering(only on H and V channels) to seperate my laserdot. This works fairly robust.

    public Mat onCameraFrame(CvCameraViewFrame cvf) {
        // Grab the video frame
        cvf.rgba().copyTo(originalFrame);
        cvf.rgba().copyTo(frame);

        // Convert it to HSV
        Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGB2HSV);

        // Split the frame into individual components (separate images for H, S,
        // and V)
        mChannels.clear();
        Core.split(frame, mChannels); // Split channels: 0-H, 1-S, 2-V
        frameH = mChannels.get(0);
        // frameS = mChannels.get(1);
        frameV = mChannels.get(2);

        // Apply a threshold to each component
        Imgproc.threshold(frameH, frameH, 155, 160, Imgproc.THRESH_BINARY);
        // Imgproc.threshold(frameS, frameS, 0, 100, Imgproc.THRESH_BINARY);
        Imgproc.threshold(frameV, frameV, 250, 256, Imgproc.THRESH_BINARY);

        // Perform an AND operation 
        Core.bitwise_and(frameH, frameV, frame);

        // Display the result.
        frameH.release();
        // frameS.release();
        frameV.release();
        frame.release(); 
        return originalFrame;
    }

Now I'm trying to get coordinates of the center of my laserdot. I tried using the findContours function on my frame but this results in multiple dots.

I hope someone could point me in the right direction providing some tips for filters to use next.

Below is a screenshot showing a processed frame. Processed frame

Wouter
  • 652
  • 2
  • 7
  • 27
  • An example frame after it's been processed with the above code would help. Perhaps with the contours marked. – beaker Nov 04 '14 at 20:53
  • I've editted my question with a screenshot showing the tracking of a red laser dot. – Wouter Nov 04 '14 at 21:04
  • I only see one contour, so that should be what you're looking for, right? In c++ I'd use `moments` on the contour to find the center of mass like so: http://docs.opencv.org/2.4.2/doc/tutorials/imgproc/shapedescriptors/moments/moments.html. – beaker Nov 04 '14 at 21:13
  • I've tried this method before but the center point gained is too variable. Any other options? – Wouter Nov 05 '14 at 11:52
  • 1
    Use the [bounding box](http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html) [technique](http://stackoverflow.com/a/14734557/176769) and you'll be good to go. – karlphillip Nov 07 '14 at 01:17
  • You can use HoughCircle method for detecting dots, and you can get the coordinate from it. – Mehmet Taha Meral May 19 '16 at 21:18

1 Answers1

0

Finally went with the bounding box technique mentioned by karlphilip above.

Wouter
  • 652
  • 2
  • 7
  • 27