0

Here is the ColorBlobDetectionActivity class of the color blob detection sample, and the particular chunk of code that I am facing difficulty in understanding is Line#114 to Line # 135 in the onTouch method implemented in this class.

When the onTouch method is invoked, that is when the user touches a colored blob, the int rows= mRgba.rows() and int cols = mRgba.cols() is calculated. Since mRgba is a Mat which was returned by onCameraFrame(), it means it represents a camera frame.So I think rows and cols now represent the number of pixels along x-axis, and that along y-axis of the frame.

Since a frame is the area viewed by the camera (which in this app is the full screen of the device), so rows and cols represent the number of pixels along x-axis and y-axis of the screen respectively.

The next two statements are:

int xOffset = (mOpenCvCameraView.getWidth() - cols) / 2;
int yOffset = (mOpenCvCameraView.getHeight() - rows) / 2;

The questions are:

  1. What exactly do xOffset and yOffset represent?

  2. mOpenCvCameraView is an instance of CameraBridgeViewBase, which according to the documentation is a basic class responsible for implementing the interaction of Camera and OpenCV. The documentation on getWidth() and getHeight() is silent, but I think it is also the width and height of the camera frame (in pixels?), so it should be same as rows and cols. Is that correct?

  3. Can you explain a bit the formula they have used to calculate xOffset and yOffset (in the above two statemnets)?

1 Answer 1

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.

1
  • When the camera view is fullscreen (see Line#70), the delivered frame should be equal to the screen's dimensions, or I am not understanding the word "Frame" clearly, but according to the Definition # 5 here, "a frame is the image that is sent to the display image rendering devices."
    – Solace
    Commented Dec 5, 2015 at 23:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.