Cv_image_elem reads the pixels of a certain point

Source: Internet
Author: User
Tags scale image

 

You can use macros defined by opencv to extract pixel values.
Assume that the gray-scale image can be used to access the pixels in column J of its line I: cv_image_elem (image, uchar, Y, X)
For a color image
Cv_image_elem (image, uchar, Y, 3 * X)
Cv_image_elem (image, uchar, Y, 3 * x + 1)
Cv_image_elem (image, uchar, Y, 3 * x + 2)

 

Cv_image_elem is a macro,

# Define cv_image_elem (image, elemtype, row, col )\
(Elemtype *) (image)-> imagedata + (image)-> widthstep * (ROW) [(COL)])

# Define cv_mat_elem (MAT, elemtype, row, col )\
(* (Elemtype *) cv_mat_elem_ptr_fast (MAT, row, Col, sizeof (elemtype )))

Well, I have always used it as a function. Actually, there is no difference in nature.

However, to correctly obtain the pixel value of the image coordinate (x, y) point, we should write cv_image_elem (image, uchar, Y, x) in this way)

Note that the order of the coordinate XY of the pixel points and the value of the row and column is the opposite (you can think carefully about why)

I have been writing cv_image_elem (image, uchar, x, y) at the beginning, and sometimes it takes a long time to make an error when I access the image,

However, you can copy the image data to the mat as follows:
Cv_image_elem (pimage, uchar, I, j) = cv_mat_elem (* mat, uchar, I, j)

No need to change order

In short, if an error is reported when the macro is applied, try to change the order or check whether the accessed address is out of bounds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.