android - OpenCV(Android) - 删除绘制的轮廓

标签 android opencv java-threads

应用程序检测框架上的特定颜色并使用 OpenCV 绘制轮廓。当点击捕获按钮时,框架图像将被用来做一些图像处理,而绘制的轮廓也被框架捕获,这不是我想要的。 我的问题是如何删除单击捕获按钮时绘制的轮廓。或者有什么方法可以得到不画轮廓的框架?

我试过的方法:

  1. 锁定 onCapture() 直到调用 onCameraFrame 并返回 mRbg 在调用 drawContour() 之前。
  2. 将mRgba 克隆到新的Mat 并将新的Mat 作为subColor 的参数

但是他们两个都没有用。

我正在考虑暂停 onCapture() 直到调用 onCameraFrame 并完成多次跳过绘制轮廓线以确保框架上没有绘制任何内容。但是我不知道如何处理两个 synchronized()。

public boolean onTouch(View v, MotionEvent event) {
    lock = true;
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        //do something
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        //do something
        //↓to make sure onCameraFrame is pause before the finger left the screen
        lock = false;
        synchronized (locker) { locker.notify(); }
    }

    return true;
} 

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    //Pause until onTouch() is done
    commandLocker();

    //Detect the contour
    mDetector.setHsvColor(txtHsv);
    if (area) {
        nRgba = mRgba.submat(ey, sy, sx, ex);
        mDetector.process(nRgba);
    } else {
        mDetector.process(mRgba);
    }

    //Skip this when onCapture is called
    //Draw the contour on the frame
    if (!capture) {
        List<MatOfPoint> contours = mDetector.getContours();
        if (nRgba != null && area) {
            Imgproc.rectangle(mRgba, new Point(sx, sy), new Point(ex, ey), areaColor, 3);
            Imgproc.drawContours(nRgba, contours, -1, contourColor);
        } else
            Imgproc.drawContours(mRgba, contours, -1, contourColor);
    }

    return mRgba;
}

public void onCapture(View view) throws IOException {
    capture = true;
    //Pause until onCameraFrame() done
    if (!area)
        subColor(mRgba);
    else
        subColor(nRgba);
}

public void subColor (Mat src) throws IOException {
    //do something
}

private void commandLocker() {
    synchronized (locker) {
        while (lock) {
            try {
                locker.wait();
            } catch (InterruptedException e) {
                Log.e("Exception", "InterruptedException");
            }
        }
    }
}

Frame captured without processing Processed image

最佳答案

在您的 onCameraFrame(CvCameraViewFrame inputFrame) 函数中,如果条件:

if (nRgba != null)

不满意,您通过执行 Imgproc.drawContours(mRgba, contours, -1, contourColor);

覆盖原始垫子 mRgba

这是你的问题吗?

关于android - OpenCV(Android) - 删除绘制的轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41959546/

相关文章:

android - 如何从一项 Activity 中获取值(value)到另一项 Activity

Android 设备在命中断点后几秒钟与调试器断开连接

opencv - OpenCV查找此图像的轮廓以进行裁剪和旋转

java - 如何使用 "implements Runnable"调用特定套接字线程中的方法?

android - 如何解决 "Layout has more than 80 views, bad for performance"?

android - Flutter Android 和 IOS 的不同设计

java - OpenCV Java.多个图像并排

c++ - 循环显示图像 vector

Java:由 HTTP 连接创建的等待连接线程存活时间很长

java - 使用带有 Join 的线程在 Java 中打印 ABC