You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
3.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include <opencv2/opencv.hpp>
#include "NeoArithStandardDll.h"
class SimTargetImage_Y16
{
public:
SimTargetImage_Y16(int w,int h);
~SimTargetImage_Y16();
public:
void setBackGround(int gray,int std);
void addTarget(int x, int y, int w, int h, int gray);
// 获取Y16数据
unsigned short* getImageData();
cv::Mat getMatRGB();
private:
cv::Mat Y8Mat;//显示图像
unsigned short* pSrc;
int nImageWidth;
int nImageHeight;
};
// 目标结构体
struct Target {
float x, y; // 目标位置
float width, height; // 目标尺寸
float vx, vy; // 水平和垂直速度
float vw, vh; // 尺寸变化速度
cv::Scalar color; // 目标颜色(适用于 RGB
bool useTexture; // 使用贴图
cv::Mat texture_cur; // 贴图
cv::Mat alaph_cur; // 贴图alaph
// 保存原始贴图状态
cv::Mat texture; // 贴图
cv::Mat alaph; // 贴图alaph
Target()
{
};
void updatePosition(int frameWidth, int frameHeight)
{
// 更新位置
x += vx;
y += vy;
width += vw;
height += vh;
// 检测边界并反弹
if (x <= width || x + width >= frameWidth) vx = -vx;
if (y <= height || y + height >= frameHeight) vy = -vy;
// 保持目标在图像范围内
x = std::max(0.0f, std::min(x, frameWidth - width));
y = std::max(0.0f, std::min(y, frameHeight - height));
}
void updateTexture()
{
if(useTexture && (texture_cur.cols != height || texture_cur.rows != width))
{
texture_cur = cv::Mat(height,width,CV_8UC3);
alaph_cur = cv::Mat(height,width,CV_8UC1);
cv::resize(texture,texture_cur,cv::Size(width,height));
cv::resize(alaph,alaph_cur,cv::Size(width,height));
}
}
void addTexture(unsigned char* png_data,int Len)
{
std::vector<uchar> img_data(png_data, png_data + Len);
cv::Mat pic = cv::imdecode(img_data, cv::IMREAD_UNCHANGED);
// cv::imshow("pic",pic);
// cv::waitKey(0);
// 分离前景的 RGB 和 Alpha 通道
cv::Mat bgr, alpha;
std::vector<cv::Mat> channels(4);
cv::split(pic, channels);
cv::merge(std::vector<cv::Mat>{channels[0], channels[1], channels[2]}, bgr);
useTexture = true;
alaph = channels[3]; // Alpha 通道
texture = bgr;
alaph_cur = channels[3];
texture_cur = bgr;
}
};
class SimTargetImage
{
public:
SimTargetImage(int w,int h);
~SimTargetImage(){};
public:
// 状态更新
void update();
// 设置背景
void setBackGround(int gray,int std);
// 增加一个目标
void addTarget(Target t);
// 增加一个遮挡
void addOcc(Target t);
public:
cv::Mat getImageRGB();
cv::Mat getImageY16();
cv::Mat getImageY8();
cv::Mat getImageNV12();
Target* getTarget(int id);
private:
void drawObj(Target t);
void drawOcc(Target t);
cv::Mat m_BaseMat;//图像帧(RGB)
cv::Mat m_CurMat;//图像帧(RGB)
std::vector<Target> m_targetList;
std::vector<Target> m_OccList;
int m_imgW;
int m_imgH;
// 各类型输出结果
private:
cv::Mat matY8;
cv::Mat matY16;
cv::Mat matNV12;
};
// 16位调光
void Map16BitTo8Bit(unsigned short* psh16BitData, long lDataLen, unsigned char* pby8BitData);
void showArithInfo(cv::Mat src,ARIDLL_OUTPUT* output);