6 Star 35 Fork 20

永军/MIP

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Tool.cpp 2.94 KB
一键复制 编辑 原始数据 按行查看 历史
DeepModel 提交于 2024-03-05 16:43 +08:00 . 增加所有代码
#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());
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/DeepModel/mip.git
git@gitee.com:DeepModel/mip.git
DeepModel
mip
MIP
master

搜索帮助