I am new to Opencv and java I'm trying to understand the onTouch method of Coloblobdetection of OpenCv. So far I have managed to define the purpose of some line and the other methods but I wont go to the **step-by-step**. If someone kindly at least help me understand the function of the lines below (specially the **//????**); what it does or what is its purpose ? I won't ask for the step-by-step but if someone could provide it is also fine.
startTime = System.currentTimeMillis();// <- start elapsed time millisec;
int cols = mRgba.cols(); //gets the columns of pixels depending of resolution
int rows = mRgba.rows(); //gets the rows of pixels depending of resolution
//Toast.makeText(this,cols+" "+ rows,Toast.LENGTH_SHORT).show();
int xOffset = (mOpenCvCameraView.getWidth() - cols) / 2; //offsets are 0; distance (displacement) between the beginning of the object and a given element or point x,y axis
int yOffset = (mOpenCvCameraView.getHeight() - rows) / 2;
//Toast.makeText(this,"X offset "+xOffset+" Y offset "+yOffset,Toast.LENGTH_SHORT).show(); //<-- offset is always 0
int x = (int)event.getX() - xOffset;
int y = (int)event.getY() - yOffset;
//Toast.makeText(this,"X-axis: "+x+" Y-axis: "+y, Toast.LENGTH_SHORT).show();
Log.i(TAG, "Touch image coordinates: (" + x + ", " + y + ")");
if ((x < 0) || (y < 0) || (x > cols) || (y > rows)) return false; // <-- ?????
Rect touchedRect = new Rect();
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;
Mat touchedRegionRgba = mRgba.submat(touchedRect); //???
Mat touchedRegionHsv = new Mat();
Imgproc.cvtColor(touchedRegionRgba, touchedRegionHsv, Imgproc.COLOR_RGB2HSV_FULL);
// Calculate average color of touched region
mBlobColorHsv = Core.sumElems(touchedRegionHsv);
int pointCount = touchedRect.width*touchedRect.height;
for (int i = 0; i < mBlobColorHsv.val.length; i++)
mBlobColorHsv.val[i] /= pointCount;
mBlobColorRgba = converScalarHsv2Rgba(mBlobColorHsv);
Log.i(TAG, "Touched rgba color: (" + mBlobColorRgba.val[0] + ", " + mBlobColorRgba.val[1] +
", " + mBlobColorRgba.val[2] + ", " + mBlobColorRgba.val[3] + ")");
mDetector.setHsvColor(mBlobColorHsv);
Imgproc.resize(mDetector.getSpectrum(), mSpectrum, SPECTRUM_SIZE);
mIsColorSelected = true;
touchedRegionRgba.release();
touchedRegionHsv.release();
↧