gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:14:53 26 4
gpt4 key购买 nike

应用程序检测框架上的特定颜色并使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com