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.