Files
HPPA/HPPA/image2display.cpp
tangchao0503 a629115e91 add
1、添加corning 410控制;
2、通过 IrisMultiMotorController 添加一轴马达控制,通过配置文件控制马达个数和马达初始化参数;

fix
1、修复点击显示光谱bug;
2、修复机械臂bug;
2025-05-15 16:40:42 +08:00

195 lines
5.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "stdafx.h"
#include "image2display.h"
#include <iostream>
CImage::CImage(QWidget* pParent) :QObject(pParent)
{
m_QRgbImage = nullptr;
m_matRgbImage = nullptr;
m_matFocusGrayImage = nullptr;
m_qimageFocusGrayImage = nullptr;
}
void CImage::SetRgbImageWidthAndHeight(int BandCount, int Sample, int FrameNumber)
{
using namespace cv;
if (m_QRgbImage != nullptr)
{
delete m_QRgbImage;//有问题????????????????????????????????????????????????
}
//m_QRgbImage = new QImage(Sample, FrameNumber, QImage::Format_RGB888);
if (m_matRgbImage != nullptr)
{
delete m_matRgbImage;
}
m_matRgbImage = new Mat(FrameNumber, Sample, CV_16UC3, Scalar(0, 0, 0));
if (m_qimageFocusGrayImage == nullptr)
{
m_qimageFocusGrayImage = new QImage(Sample, BandCount, QImage::Format_RGB32);
}
if (m_matFocusGrayImage == nullptr)
{
m_matFocusGrayImage = new Mat(BandCount, Sample, CV_16U, Scalar(0));
//cv::Mat matAdjustPreview = Mat::zeros(BandCount, Sample, CV_16U);
}
//cv::Mat matAdjustPreview = Mat::zeros(BandCount, Sample, CV_16U);
//m_matFocusGrayImage = matAdjustPreview;
std::cout << "设置帧数:" << FrameNumber << std::endl;
m_iFrameCounter = 0;//每次都重置为0
m_iSampleNumber = Sample;
m_iBandNumber = BandCount;
m_iFrameNumber = FrameNumber;
//std::cout << "rgb影像内存地址为" << m_QRgbImage << std::endl;
}
void CImage::FillRgbImage(unsigned short *datacube)
{
//uchar==unsigned char内存大小1个字节范围为0-255
//uchar * imagebits24 = m_QRgbImage->bits();
//uchar * imagebits24 = m_QRgbImage->scanLine(m_iFrameCounter);//??????????????????????????????????????????????????????????????????????
unsigned short r, g, b;
for (int j = 0; j < m_iSampleNumber; j++)
{
//std::cout << "rgb图像写入数据帧数" << j << std::endl;
//取值一帧影像中从左到右的rgb像元值
r = *(datacube + 121 * m_iSampleNumber + j);
g = *(datacube + 79 * m_iSampleNumber + j);
b = *(datacube + 40 * m_iSampleNumber + j);
//将像元值赋值到cv::Mat中操作像元值https://zhuanlan.zhihu.com/p/51842288
//int dataType = m_matRgbImage->type();//当数据类型为CV_16UC3时返回18
//std::cout << "m_matRgbImage数据类型为" << dataType << std::endl;
if (m_matRgbImage->type() == CV_16UC3)
{
//std::cout << "操作像素值!" << std::endl;
m_matRgbImage->at<cv::Vec3w>(m_iFrameCounter, j)[2] = r;
m_matRgbImage->at<cv::Vec3w>(m_iFrameCounter, j)[1] = g;
m_matRgbImage->at<cv::Vec3w>(m_iFrameCounter, j)[0] = b;
}
////将像元值从4095归一化到255的范围并赋值到QImage中
//imagebits24[j * 3] = uchar(r * 255 / 4095);
//imagebits24[j * 3 + 1] = uchar(g * 255 / 4095);
//imagebits24[j * 3 + 2] = uchar(b * 255 / 4095);
}
m_iFrameCounter++;
//保存rgb图片
if (m_iFrameCounter % m_iFramerate == 0 || m_iFrameCounter == m_iFrameNumber - 1)
{
////保存文件
//FileOperation * fileOperation = new FileOperation();
//string directory = fileOperation->getDirectoryOfExe();
//string rgbFilePathStrech = directory + "\\tmp_image_strech.png";//没有拉伸图片
//string rgbFilePathNoStrech = directory + "\\tmp_image_no_strech.png";//拉伸图片
//m_QRgbImage->save(QString::fromStdString(rgbFilePathNoStrech), "PNG");
//ImageProcessor imageProcessor;
//cv::imwrite(rgbFilePathNoStrech, *m_matRgbImage);
//cv::imwrite(rgbFilePathStrech, imageProcessor.CStretch(*m_matRgbImage, 0.02));
}
}
void CImage::FillFocusGrayImage(unsigned short * datacube)
{
int rowCount = m_matFocusGrayImage->rows;
int colCount = m_matFocusGrayImage->cols;
for (unsigned short i = 0; i < m_matFocusGrayImage->rows; i++)
{
for (unsigned short j = 0; j < m_matFocusGrayImage->cols; j++)
{
//m_matFocusGrayImage->at<ushort>(i, j) = *(datacube + m_matFocusGrayImage->cols*i + j);
m_matFocusGrayImage->at<ushort>(i, j) = datacube[m_matFocusGrayImage->cols*i + j];
}
}
//int rowCount = m_matFocusGrayImage.rows;
//int colCount = m_matFocusGrayImage.cols;
////memcpy(m_matFocusGrayImage.data, datacube, rowCount*colCount);
//for (unsigned short i = 0; i < m_matFocusGrayImage.rows; i++)
//{
// for (unsigned short j = 0; j < m_matFocusGrayImage.cols; j++)
// {
// m_matFocusGrayImage.at<ushort>(i, j) = *(datacube + m_matFocusGrayImage.cols*i + j);
// //m_matFocusGrayImage.at<ushort>(i, j) = datacube[colCount*i + j];
// }
//}
//将mat保存成文件
//cv::imwrite("D:/delete/2222222222/test.bmp", m_matFocusGrayImage);
}
void CImage::FillFocusGrayQImage(unsigned short * datacube)
{
float two_eight = pow(2.0, 8);
float two_sixteen = pow(2.0, 12);
int width = m_qimageFocusGrayImage->width();
int height = m_qimageFocusGrayImage->height();
for (unsigned short i = 0; i < height; i++)
{
for (unsigned short j = 0; j < width; j++)
{
//uint tmp = (two_eight* *(datacube + width * i + j)) / two_sixteen;
uint tmp = (two_eight* datacube[width*i + j]) / two_sixteen;
//uint tmp = datacube[width*i + j];
//m_qimageFocusGrayImage->setPixel(j, i, tmp);
m_qimageFocusGrayImage->setPixel(j, i, qRgb((unsigned char)tmp, (unsigned char)tmp, (unsigned char)tmp));
}
}
//m_qimageFocusGrayImage->save("D:/delete/2222222222/test.bmp");
/*float two_eight = pow(2.0, 8);
float two_sixteen = pow(2.0, 16);
QImage *qi = new QImage(imwidth, imheight, QImage::Format_RGB32);
for (int i = 0; i < imheight; i++)
{
for (int j = 0; j < imwidth; j++)
{
floatData[i*imwidth + j] = (two_eight* floatData[i*imwidth + j]) / two_sixteen;
qi->setPixel(j, i, qRgb((unsigned char)floatData[i*imwidth + j], (unsigned char)floatData[i*imwidth + j], (unsigned char)floatData[i*imwidth + j]));
}
}*/
}