Using opencv in QT to process the conversion between image qimage and iplimage

Source: Internet
Author: User

It is not a problem when using opencv to process images displayed on the qt label.

1. qimage must be used for display on QT.

Convert iplimage to qimage

Color Image Conversion

Iplimage * fram;

Qimage image (const uchar *) fram-> imagedata, fram-> width, fram-> height, qimage: format_rgb888 );

After using opencv binarization, you can switch it and find that multiple images and colors are displayed in the label.

At this time, you have to change the parameters.

Qimage resimg (uchar *) RES-> imagedata, res-> width, res-> height, qimage: format_indexed8 );

After the parameter is changed, qimage: format_indexed8 is used to convert the gray image.

2. Convert the data image collected by YUV camera to RGB to generate qimage. I want to convert it to lplimage format using opencv. At this time, I can write it like this.

// Convert the format qimage to iplimage
Width = frame-> width ();
Height = frame-> height ();
Size. Height = height;
Size. width = width;
Lplimage * image = cvcreateimage (size, ipl_depth_8u, 3 );
For (INT y = 0; y {
For (INT x = 0; x <width; ++ X)
{
Qrgb RGB = frame-> pixel (x, y );
Cvset2d (image, Y, X, cv_rgb (qred (RGB), qgreen (RGB), qblue (RGB )));
}
}

Finally, the image is in the iplimage format. You can encapsulate the above and directly call each time.

Using opencv in QT to process the conversion between image qimage and iplimage

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.