(OpenCV Study) Mat point access method, get pixel

1. At approach

Mat image (ROW, COL, CV_TYPE);
image.at (WANT_ROW, WANT_COL);

- ROW: Row
- COL: Column
- CV_TYPE: data type ( for example : CV_8UC3 = 8 bit 3 channels)
- DATA_TYPE: Mat creation data type ( for example : float, usigned char)
- WANT_ROW: access to the desired row
- WANT_COL: access to the desired column

[Advantage]: Access after validation progress , so safe and accurate approach .
[Disadvantage]:  most slow in 3 ways.

2. Ptr approach
Mat image (ROW, COL, CV_TYPE);
image.ptr (WANT_ROW, WANT_COL); (This access is changed to the Point)

- ROW: Row
- COL: Column- CV_TYPE: data type ( for example : CV_8UC3 = 8 bit 3 channels)
- DATA_TYPE: Mat creation data type ( for example : float, usigned char)
- WANT_ROW: access to the desired row
- WANT_COL: access to the desired column

[Advantage]: Access is faster than first way.
[Disadvantage]: direct access to the data , but way slower than third way .



3. Data approach
Mat image (ROW, COL, CV_TYPE);
DATA_TYPE * data = (DATA_TYPE *) image.data;data [WANT_ROW * image.cols + WANT_COL]

- ROW: Row
- COL: Column
- CV_TYPE: data type ( for example : CV_8UC3 = 8 bit 3 channels)
- DATA_TYPE: Mat creation data type ( for example : float, usigned char)
- WANT_ROW: access to the desired row
- WANT_COL: access to the desired column

[Advantage]: very fast.
[Disadvantage]: not check validation ,  it is hard to know inadequate access.


This is sample code.
http://study.marearts.com/2016/06/opencv-pixel-access-at-ptr-data.html

Comments

Popular posts from this blog

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

OpenCV Stitching example (Stitcher class, Panorama)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

Optical Flow sample source code using OpenCV

OpenCV Drawing Example, (line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours)

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

SICK LMS511 sensor data acquisition interface (source code, C++/MFC)

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Image warping (using opencv findHomography, warpPerspective)