문제 설명
이 OpenCV4Android 샘플 애플리케이션에서 이 코드는 무엇을 합니까? (What does this piece of code do in this OpenCV4Android sample application?)
색상 얼룩 감지 샘플의 ColorBlobDetectionActivity
클래스와 내가 이해하기 어려운 특정 코드 덩어리는 onTouch
메소드.
onTouch
메소드가 호출될 때, 즉 사용자가 컬러 블롭을 터치할 때, int rows= mRgba.rows()
및 int cols = mRgba.cols()
가 계산됩니다. mRgba
는 <에 의해 반환된 Mat
이기 때문에 code>onCameraFrame(), 그것은 카메라 프레임을 나타낸다는 것을 의미합니다. 따라서 rows
와 cols
는 이제 x축을 따라 픽셀 수를 나타내고, 프레임의 y축을 따라
프레임은 카메라가 보는 영역(이 앱에서는 기기의 전체 화면임)이므로 rows
와 cols
는 다음을 나타냅니다. 각각 화면의 x축과 y축에 따른 픽셀 수입니다.
다음 두 문장은 다음과 같습니다.
int xOffset = (mOpenCvCameraView.getWidth() ‑ cols) / 2;
int yOffset = (mOpenCvCameraView.getHeight() ‑ rows) / 2;
질문은 다음과 같습니다.
xOffset
및yOffset
은 정확히 무엇을 나타냅니까?mOpenCvCameraView
CameraBridgeViewBase의 인스턴스입니다. "nofollow">문서는 Camera와 OpenCV의 상호 작용을 구현하는 기본 클래스입니다. 문서getWidth()
및getHeight()
의 는 무음이지만 카메라 프레임의 너비와 높이(픽셀 단위)이기도 하므로row
및col
과 동일해야 합니다. 맞나요?
참조 솔루션
방법 1:
The delivered frames and the surface size are not necessarily the same. The maximum of the event.getX equals to the surface width.
I haven't seen the program running, but it seems like the offset determines the size of the touched rect. The rect is used for averaging the color, not simply displaying a single pixel's data.
(by Solace、Mice Pápai)
참조 문서