* true means conversion was successful, false means conversion failed.īool QImage2HImage(QImage &from, HalconCpp::HImage &to) The memory is reallocated for to each time. * to HImage output, from and to do not share memory data. * QImage2HImage converts Qt QImage to Halcon HImage For color images, the following functions can be used:
Halcon qt how to#
The point of knowledge here is how to construct HImage after getting the data of QImage. Reinterpret_cast(&B), &Type, &width, &height) Memcpy( to.bits(), pSrc, static_cast(width) * static_cast(height) ) įrom.GetImagePointer3(reinterpret_cast(&R), Unsigned char * pSrc = reinterpret_cast( from.GetImagePointer1(&Type, &width, &height) ) If(to.width() != width || to.height() != height || to.format() != format) If( strcmp(type.S(), "byte" ))//If it is not of type byte, it fails * true means conversion was successful, false means conversion failedīool HImage2QImage(HalconCpp::HImage &from, QImage &to) If the memory size of to is appropriate, there is no need to reallocate memory. * to QImage, where from and to do not share memory. * from HImage, temporarily only supports 8bits grayscale image and 8bits 3-channel color image * HImage2QImage converts Halcon's HImage to Qt's QImage If it is a grayscale image, you can use HImage::GetImagePointer1 to get the first address of the image data. My approach is to allocate appropriate data space to QImage first. At the end of this article, I will also briefly introduce how to share data. Of course, if it is only a grayscale image, the data can be shared. Therefore, the image data is copied in the following code. Due to the huge difference between HImage and QImage when storing color images in memory, it is difficult to share the same image data between these two classes. And HImage does not support Alpha channel. The rest is rarely used, so I won't consider it for now.Įach component of the color image in HImage is stored separately.
Halcon qt code#
In my code implementation, only RGB888 and RGB32 are supported. QImage supports many types of color images, such as RGB888, RGB555, RGB565, RGB32, etc. For example, in the RGB32 format, the three color components of RGB are packed into a 32-bit dword, and then the pixels are sequentially stored in the memory in a row major manner. The components of the color image in QImage are stored alternately. But for color images, the storage method is very different. For grayscale images, the storage methods of these two classes are similar, and both are a large array. Qt uses QImage to store image data, and Halcon uses HImage. Today I spent half a day studying how to transfer image data between Halcon and Qt. So I decided to use C++ Qt for my program, and only use the operators provided by Halcon where visual algorithms are needed.
Halcon qt software#
If you want to develop software interfaces or interact with other programs, Halcon is not very good at it. But Halcon, like OpenCV, focuses on visual algorithms. Writing algorithms in Halcon is much more convenient than OpenCV. Recently, I started learning Halcon due to some chance. I have always used OpenCV to develop machine vision algorithms in the past. Conversion between Halcon HImage and Qt QImage