Use the opencv C ++ interface to copy the ROI data.

Source: Internet
Author: User

The use of pencv images and sub-images in 1.x is very different from that in 2.x.

1. Version X is implemented by using cvcopy, cvsetimageroi, cvcopy, and cvresetimageroi.

Later than version 2.x, images are represented by mat. There are many ways to copy images, such

SRC. Clone ()

SRC. copyto (DST)

SRC. copyto (DST, mask)

When the DST and SRC types are the same, you can directly create and copy image data (deep copy ),

SRC. convertize (DST, type, scale, shift)

When SRC. Depth = DST. Depth and noscale, it is equivalent to copyto (create and copy); others, convert and copy data.

------------

The idea of using the 1.x version to copy the sub-Image ROI is quite difficult.

The mat image provides adjustroi to change the Image ROI, but it is inconvenient to use. If the 1.x version is used, converting the image from mat to iplimage is more troublesome.

However, mat provides a reference method to obtain sub-image data. For example

M. Row (I), M. COL (H), M. rowrange (), M. colrange (), all of which are derived from

M (ROI), create a new mat header, and do not copy image data. Return the reference of the ROI sub-image.

In this way, it is much easier to copy the ROI of an image to the specified region of another image. As shown in opencv

Rect r (1, 1, 10, 20); // specify the ROI sub-image area of SRC
Mat dstroi = DST (rect (, R. Width, R. Height); // get the reference of the sub-image in the specified area of DST
SRC (R). convertify (dstroi, dstroi. Type (), 1, 0); // copy between ROI sub-Images

In this case, you do not need to specify the ROI of the image, so the computation is convenient and clear.

-------------

PS: M. reshape changes the dimension (number of channels) of the image, but does not change the data of the original image. The principle is to change the mat header information to obtain the sub-image reference, but not copy the image data.

The repeat () and flip () operations will create a new DST image and copy the SRC data.

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.