Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create and assign images in Qt+OpenCV joint development

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly analyzes the relevant knowledge points about the creation and assignment of images in the joint development of Qt+OpenCV. The content is detailed and easy to understand, and the operation details are reasonable, which has a certain reference value. If you are interested, you might as well follow the editor to take a look, and follow the editor to learn more about the creation and assignment of images in Qt+OpenCV joint development.

I. the basic structure of Mat

1. Mat is not only a very useful image container class, but also a general matrix class. Its mat is divided into header (including image size, width and height, type, channel number, etc.) and data part (collection of pixel values).

2. When the acquired mat object is assigned to another object, it is equivalent to pointing the pointer back to the original data, essentially pointing to the same DataBlock. Only when you clone or copy will you make a copy of all the data in this Mat for your use. The basic structure of Mat is shown in the figure.

Add:

1. The data part mainly contains the pixel data of the image and the pixel value of each pixel. If there is a single channel, each pixel has only one value; if there are three channels, each pixel has three values.

2. There are many ways to create Mat objects: clone, copy, assign, and construct functions. Speed from fast to slow: constructor, assignment, copy, clone

Assignment method: the object generated by the assignment points to the same memory address Data Block as the original assignment object. (shallow copy) Copy/clone method: a new memory object that is generated, pointing to a separate Data Block. (deep copy) Constructor: Mat img_constructe (src); / / src is the source address of the image

The following is mainly about the cloning and copying of images.

2. Cloning and copying of images. 1. Clone function

Mat img_clone = src.clone ()

2. CopyTo function

C++ prototype:

Parameter 1: OutputArray, target matrix (output image).

3. Example

As before, the declaration function is placed in the test1.h file and the implementation is placed in the test1.cpp file

Testing in main

As you can see from the picture below, there is no difference between the two pictures shown.

3. Create an image 1. Create a blank image:

As shown in the figure

The function prototype of zeros here:

Parameter 1: size, matrix (image) size.

Parameter 2: type, image type

The source code of OpenCv mentions: (_ type is CV_8UC1, CV_64FC3, CV_32SC (12) etc.)

CV_8UC1,CV_64FC3 is an enumerated type, so the type here can be any predefined type, with the following structure:

CV_ (S | U | F) C

1. The number of bit_depth- bits-represents 8 bite1, 16 bites1, 32 bites, 64 bites

If you now create a Mat object that stores a grayscale image, which is 100 in width and 100 in height, then there are now 10000 pixels in this grayscale image, and each pixel occupies a space in memory space of 8 bits, which corresponds to CV_8.

2. S | U | Fmuri Smuri-represents signed int--- signed plastic surgery

Umuri-representative-- unsigned int---- unsigned plastic surgery

Fmure-representative-float- single precision floating point type

3. CMurMutel-represents the number of channels of an image, such as:

1Mel-grayscale image-grayImg--- single channel image

2--RGB color image-3-channel image

3Mel-RGB image with Alph channel-4 channel image

If these types do not have the number of channels, the default number of channels is 1.

For example, CV_8U is equivalent to CV_8UC1,CV_32S and is equivalent to CV_32SC1.

After modifying the above code to three channels:

It can be seen that the original matrix has changed from 8 × 8 to 24 × 8, because it used to be a single channel, but now it is 3 channels, which represents that each pixel contains three pixel values, indicating that the true width of the image on the Mat is equal to the number of channels multiplied by the width of the Mat definition matrix, that is, 3x8x24.

2. Create a diagram with channels of all 1:

However, a graph in which each channel is 1 cannot be used on three channels, as shown in the figure. The result is that the first channel of each pixel is 1, and the rest are 0.

In fact, we can also assign a value to m3 to change the value of its first channel.

If you want the value of each channel to be 127, you can call the Scalar function

3. The difference between copy and assignment

3.1 use Scalar function to set m3 object to green

3.2m3 assigned a value to m4 and changed M4 to yellow.

3.3 copy m3 to m4 and M4 changed to yellow

Difference: the copy does not change the original object, while the assignment changes as soon as M4 changes m3.

This is the end of the introduction on "how to create and assign images in Qt+OpenCV joint development". More related content can be searched for previous articles, hoping to help you answer questions and questions, please support the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report