如何在android opencv中将蒙版应用于实时相机

时间:2017-09-02 15:24:49

标签: android opencv camera mask opencv4android

我在获取掩码后使用Core.inRange从实时摄像头输入中检测蓝色,即当我采用bitwise_时显示阈值并且它显示重叠的帧,我怎样才能获得一帧? Frames are ovelaping for the detected object

这是我的代码:

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {       

     Imgproc.cvtColor(inputFrame.rgba(),imgHSV,Imgproc.COLOR_RGB2HSV);
          Core.inRange(imgHSV,new Scalar(100, 100, 100), new Scalar(120, 255, 
          255),imgThresholded); // Blue Color  
   Core.bitwise_and(inputFrame.rgba(),inputFrame.rgba(),tempImg,imgThresholded);
        return tempImg;
}

1 个答案:

答案 0 :(得分:1)

似乎是因为您没有清除tempImg Mat并多次使用“旧”内容。尝试将tempImg.setTo(new Scalar(0,0,0,255))添加到onCameraFrame()。这样的事情:

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {       

   tempImg.setTo(new Scalar(0,0,0,255));

   Imgproc.cvtColor(inputFrame.rgba(),imgHSV,Imgproc.COLOR_RGB2HSV);
          Core.inRange(imgHSV,new Scalar(100, 100, 100), new Scalar(120, 255, 
          255),imgThresholded); // Blue Color  
   Core.bitwise_and(inputFrame.rgba(),inputFrame.rgba(),tempImg,imgThresholded);
        return tempImg;
}