我是安卓系统的新手,两者兼而有之。但是,我尝试从相机中获取图像,将其转换为所需的格式,并将其传递给tflite模型
用于捕获图像并对其应用图像处理的代码
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
float mh = mRGBA.height();
float cw = (float) Resources.getSystem().getDisplayMetrics().widthPixels;
float scale = mh / cw * 0.7f;
mRGBA = inputFrame.rgba();
frame = classifier.processMat(mRGBA);
Mat temp = new Mat();
Mat temp3= new Mat();
if (!isDebug) {
if (counter == CLASSIFY_INTERVAL) {
Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGBA2GRAY);
Core.rotate(frame, frame, Core.ROTATE_90_CLOCKWISE);
Imgproc.GaussianBlur(frame, frame, new Size(5, 5), 0);
Imgproc.adaptiveThreshold(frame, frame, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY_INV , 3, 2);
Bitmap bmsp = null;
runInterpreter();
counter = 0;
} else {
counter++;
}
}
Imgproc.rectangle(mRGBA,
new Point(mRGBA.cols() / 2f - (mRGBA.cols() * scale / 2),
mRGBA.rows() / 2f - (mRGBA.cols() * scale / 2)),
new Point(mRGBA.cols() / 2f + (mRGBA.cols() * scale / 2),
mRGBA.rows() / 2f + (mRGBA.cols() * scale / 2)),
new Scalar(0, 255, 0), 1);
if (isEdge) {
mRGBA = classifier.debugMat(mRGBA);
}
System.gc();
return mRGBA;
}
我的输出看起来像这个图像,但我希望在将手传递给模型之前用白色填充手。有人能建议吗
主要问题是
adaptiveThreshold
的结果在外部边缘中有间隙,因此不能将其用作findContours
的输入我认为使用
GaussianBlur
会让事情变得更糟,因为它会模糊手和背景之间的边缘您可以使用以下阶段:
adaptiveThreshold
(我使用的是大小51)。使用较大的内核大小,保持一条没有间隙的粗边线(指甲处的小间隙除外)李>
找到具有最大面积的轮廓李>
有一个问题:由于轮廓形状怪异,手的内部没有填充李>
找到轮廓的中心,并使用
floodFill
填充它李>下面是一个Python代码示例:
结果:
thres_gray
:res
在floodFill
之前:res
在floodFill
之后:JAVA实现:
相关问题 更多 >
编程相关推荐