2014-11-04 86 views
0

我想跟踪在Android设备上使用OpenCV的激光点。我想用这个laserdot画一个放在我的cameraview上的画布。OpenCV Android轨道激光点

我已将我的camerapreview转换为HSV色彩空间,并使用阈值过滤(仅在H和V通道上)来分隔我的laserdot。这工作相当健壮。

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; 
    } 

现在我试图获得我的laserdot中心坐标。我试图在我的框架上使用findContours函数,但这会导致多个点。

我希望有人能指点我正确的方向,提供一些提示,以便接下来使用的过滤器。

下面是显示处理帧的截图。 Processed frame

+0

使用上面的代码处理后的示例框架将有所帮助。也许轮廓标记。 – beaker 2014-11-04 20:53:30

+0

我已经用截屏显示跟踪红色激光点编辑了我的问题。 – Wouter 2014-11-04 21:04:34

+0

我只看到一个轮廓,所以应该是你在找什么,对吧?在C++中,我会使用轮廓上的“时刻”来查找质量中心,例如:http://docs.opencv.org/2.4.2/doc/tutorials/imgproc/shapedescriptors/moments/moments.html。 – beaker 2014-11-04 21:13:04

回答

0

最后用上面提到的karlphilip提到的包围盒技术。