gpt4 book ai didi

android - OpenCV4Android 示例应用程序 - 此代码 fragment 的作用是什么?

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

this class 中从第 129 行到第 133 行发生了什么?颜色 Blob 检测示例应用程序?

一些背景:

应用中的相机 View 如下所示:(请注意,在相机 View 中,相机框架周围有黑色边框)

Image( If you can't see the image, check it here. )

从第 114 行到第 128 行,发生了以下情况。

  1. int cols = mRgba.cols(); cols() 给出矩阵中的列数。这里的矩阵是表示正在显示的实时帧流中的帧的 Mat(而不是整个摄像机 View ),即它表示正在显示实时流的摄像机 View 部分,不包括摄像机 View 的黑色边框.

  2. int rows = mRgba.rows(); rows() 给出相机帧中的行数,不包括相机 View 的黑色边框。

  3. int xOffset = (mOpenCvCameraView.getWidth() - cols)/2; int yOffset = (mOpenCvCameraView.getHeight() - rows)/2; mOpenCvCameraView.getWidth() 给出整个相机 View 中的行数,即相机框架加上框架周围相机 View 的黑色边框。 (mOpenCvCameraView.getWidth() - cols) 给出相机 View 左右黑色边框宽度的总和。 (mOpenCvCameraView.getWidth() - cols)/2xOffset 给出一侧黑色边框的宽度,即右侧或左侧,相机的黑色边框看法。 同样适用于 yOffset

  4. int x = (int)event.getX() - xOffset; int y = (int)event.getY() - yOffset; getX() 返回第一个指针索引的此事件的 X 坐标。因此 getX() 给出了触摸区域与相机 View 最左端的距离,其中包括左侧的黑色边框。所以 event.getX()-xOffsetint x 是触摸区域与相机“框架”最左端的距离(不包括黑色相机 View 的边框)。 同样适用于 int y

然后是我不知道的台词。

最佳答案

我假设你问的是这些行:

touchedRect.x = (x>4) ? x-4 : 0;
touchedRect.y = (y>4) ? y-4 : 0;

touchedRect.width = (x+4 < cols) ? x + 4 - touchedRect.x : cols - touchedRect.x;
touchedRect.height = (y+4 < rows) ? y + 4 - touchedRect.y : rows - touchedRect.y;

据我所知,这基本上只是确保 Rectangle 的高度和宽度不会偏离框架。

分解原因 -

? Java 中的运算符(称为三元运算符)基本上是 if/else 的简写 - touchedRect.x = (x>4) ? x-4 : 0 行意味着

if (x>4) {
touchedRect.x = x-4;
} else {
touchedRect.x = 0;
}

因此,对于第 129 行,如果 x > 4 , 设置 touchedRect.xx-4 , 否则 0 .

第 130 行,如果 y > 4 , 设置 touchedRect.yy-4 , 否则 0 .

第 131 行,touchedRect.width变成 x+4 - touchedRect.x如果x+4 < cols , 否则 touchedRect.width变成 cols - touchedRect.x

第 132 行,touchedRect.height变成 y+4-touchedRect.y如果y+4 < rows , 否则它变成 rows - touchedRect.y

关于android - OpenCV4Android 示例应用程序 - 此代码 fragment 的作用是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34673743/

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