代码拉取完成,页面将自动刷新
#include "Tool.h"
#include <qDebug>
int QImageAndHobject::QImage2HImage(QImage & from, HImage & to, const char * chall)
{
if (from.data_ptr() == NULL) return false;
int width = from.width(), height = from.height();
if (from.format() == QImage::Format_RGB888)
{
to.GenImageInterleaved(from.bits(), "rgb", width, height, 0, "byte", width, height, 0, 0, 8, 0);
return true;
}
else if (from.format() == QImage::Format_Grayscale8|| from.format() == QImage::Format_Indexed8)
{
to.GenImage1("byte", width, height, from.bits());
return true;
}
else if (from.format()== QImage::Format_RGB32|| from.format() == QImage::Format_ARGB32 || from.format() == QImage::Format_ARGB32_Premultiplied)
{
to.GenImageInterleaved(from.bits(), "rgbx", width, height, 0, "byte", width, height, 0, 0, 8, 0);
return true;
}
return false;
}
void QImageAndHobject::rgb3_to_interleaved(HObject ho_ImageRGB, HObject * ho_ImageInterleaved)
{
}
void QImageAndHobject::HobjectToQImage(HObject img, QImage **Image)
{
HTuple hChannels;
HTuple width, height;
HTuple htype;
HObject imgb;
HTuple hpointer;
qDebug() << "HobjectToQImage0";
//图片类型转化为byte类型
ConvertImageType(img, &imgb, "byte");
//获取图片通道数
CountChannels(imgb, &hChannels);
qDebug() << "HobjectToQImage1";
if (hChannels[0].I() == 1)
{
qDebug() << "HobjectToQImage3";
unsigned char* ptr;
GetImagePointer1(img, &hpointer, &htype, &width, &height);
ptr = (unsigned char*)hpointer[0].L();
*(*Image) = QImage(ptr, width, height, QImage::Format_Indexed8);
}
else if (hChannels[0].I() == 3)
{
qDebug() << "HobjectToQImage2";
unsigned char* ptr3;
HObject Ho_ImageInterleaved;
rgb3_to_interleaved(img,&Ho_ImageInterleaved);
GetImagePointer1(Ho_ImageInterleaved, &hpointer, &htype, &width, &height);
ptr3 = (unsigned char*)hpointer[0].L();
*(*Image) = QImage(ptr3, width/3, height, QImage::Format_RGB888);
}
}
bool QImageAndHobject::HImage2QImage(HalconCpp::HImage & from, QImage& to)
{
return false;
}
int Tool::PixToBufferPix(char * ImageMatPath, int Pix_x, int Pix_y, int & Out_Pix_x, int & Out_Pix_y)
{
HTuple hv_FileHandle, hv_SerializedItemHandle;
HTuple hv_HomMat2D_2, hv_RowTrans, hv_ColTrans;
//读取文件地址
OpenFile(ImageMatPath, "input_binary", &hv_FileHandle);
FreadSerializedItem(hv_FileHandle, &hv_SerializedItemHandle);
DeserializeHomMat2d(hv_SerializedItemHandle, &hv_HomMat2D_2);
CloseFile(hv_FileHandle);
//坐标准换
AffineTransPixel(hv_HomMat2D_2,Pix_y ,Pix_x , &hv_RowTrans, &hv_ColTrans);
Out_Pix_x = hv_ColTrans.TupleInt();
Out_Pix_y = hv_RowTrans.TupleInt();
return 0;
}
void Tool::GetImageSizeTool(char* ImagePath,int &PutImageWidth, int &PutImageHeight)
{
HObject Image;
HTuple hv_Width, hv_Height;
ReadImage(&Image, ImagePath);
GetImageSize(Image, &hv_Width, &hv_Height);
PutImageWidth = hv_Width.TupleInt();
PutImageHeight = hv_Height.TupleInt();
std::string s(ImagePath);
s.substr(0, s.size() - 10);
//写入原图数据
WriteImage(Image,"bmp", 0, s.c_str());
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。