修复hik相机报错
This commit is contained in:
parent
cc767394b8
commit
6962892648
@ -1,9 +1,9 @@
|
|||||||
camera_name: "mindvision"
|
# camera_name: "mindvision"
|
||||||
exposure_ms: 2
|
# exposure_ms: 2
|
||||||
gamma: 0.5
|
# gamma: 0.5
|
||||||
vid_pid: "f622:d13a"
|
# vid_pid: "f622:d13a"
|
||||||
|
|
||||||
# camera_name: "hikrobot"
|
camera_name: "hikrobot"
|
||||||
# exposure_ms: 3
|
exposure_ms: 3
|
||||||
# gain: 10.0
|
gain: 10.0
|
||||||
# vid_pid: "2bdf:0001"
|
vid_pid: "2bdf:0001"
|
||||||
@ -1,5 +1,5 @@
|
|||||||
# enemy_color: "red"
|
enemy_color: "red"
|
||||||
enemy_color: "blue"
|
# enemy_color: "blue"
|
||||||
|
|
||||||
|
|
||||||
#####-----神经网络参数-----#####
|
#####-----神经网络参数-----#####
|
||||||
@ -10,7 +10,7 @@ yolov8_model_path: assets/yolov8.xml
|
|||||||
yolov5_model_path: assets/yolov5.xml
|
yolov5_model_path: assets/yolov5.xml
|
||||||
device: GPU
|
device: GPU
|
||||||
min_confidence: 0.8
|
min_confidence: 0.8
|
||||||
use_traditional: true
|
use_traditional: false
|
||||||
|
|
||||||
#####-----ROI-----#####
|
#####-----ROI-----#####
|
||||||
roi:
|
roi:
|
||||||
|
|||||||
@ -116,7 +116,21 @@ void HikRobot::capture_start()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto timestamp = std::chrono::steady_clock::now();
|
auto timestamp = std::chrono::steady_clock::now();
|
||||||
cv::Mat img(cv::Size(raw.stFrameInfo.nWidth, raw.stFrameInfo.nHeight), CV_8U, raw.pBufAddr);
|
|
||||||
|
const auto & frame_info = raw.stFrameInfo;
|
||||||
|
auto pixel_type = frame_info.enPixelType;
|
||||||
|
|
||||||
|
// Determine image type based on pixel format
|
||||||
|
int cv_type = CV_8U;
|
||||||
|
bool is_color = false;
|
||||||
|
|
||||||
|
// Check if it's a color format (RGB or BGR already converted)
|
||||||
|
if (pixel_type == PixelType_Gvsp_RGB8_Packed || pixel_type == PixelType_Gvsp_BGR8_Packed) {
|
||||||
|
cv_type = CV_8UC3;
|
||||||
|
is_color = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cv::Mat img(cv::Size(raw.stFrameInfo.nWidth, raw.stFrameInfo.nHeight), cv_type, raw.pBufAddr);
|
||||||
|
|
||||||
cvt_param.nWidth = raw.stFrameInfo.nWidth;
|
cvt_param.nWidth = raw.stFrameInfo.nWidth;
|
||||||
cvt_param.nHeight = raw.stFrameInfo.nHeight;
|
cvt_param.nHeight = raw.stFrameInfo.nHeight;
|
||||||
@ -130,16 +144,27 @@ void HikRobot::capture_start()
|
|||||||
cvt_param.enDstPixelType = PixelType_Gvsp_BGR8_Packed;
|
cvt_param.enDstPixelType = PixelType_Gvsp_BGR8_Packed;
|
||||||
|
|
||||||
// ret = MV_CC_ConvertPixelType(handle_, &cvt_param);
|
// ret = MV_CC_ConvertPixelType(handle_, &cvt_param);
|
||||||
const auto & frame_info = raw.stFrameInfo;
|
|
||||||
auto pixel_type = frame_info.enPixelType;
|
|
||||||
cv::Mat dst_image;
|
cv::Mat dst_image;
|
||||||
const static std::unordered_map<MvGvspPixelType, cv::ColorConversionCodes> type_map = {
|
const static std::unordered_map<MvGvspPixelType, cv::ColorConversionCodes> type_map = {
|
||||||
{PixelType_Gvsp_BayerGR8, cv::COLOR_BayerGR2RGB},
|
{PixelType_Gvsp_BayerGR8, cv::COLOR_BayerGR2BGR},
|
||||||
{PixelType_Gvsp_BayerRG8, cv::COLOR_BayerRG2RGB},
|
{PixelType_Gvsp_BayerRG8, cv::COLOR_BayerRG2BGR},
|
||||||
{PixelType_Gvsp_BayerGB8, cv::COLOR_BayerGB2RGB},
|
{PixelType_Gvsp_BayerGB8, cv::COLOR_BayerGB2BGR},
|
||||||
{PixelType_Gvsp_BayerBG8, cv::COLOR_BayerBG2RGB}};
|
{PixelType_Gvsp_BayerBG8, cv::COLOR_BayerBG2BGR},
|
||||||
cv::cvtColor(img, dst_image, type_map.at(pixel_type));
|
{PixelType_Gvsp_BayerRBGG8, cv::COLOR_BayerRG2BGR}};
|
||||||
|
|
||||||
|
auto it = type_map.find(pixel_type);
|
||||||
|
if (it != type_map.end()) {
|
||||||
|
cv::cvtColor(img, dst_image, it->second);
|
||||||
img = dst_image;
|
img = dst_image;
|
||||||
|
} else if (is_color && pixel_type == PixelType_Gvsp_RGB8_Packed) {
|
||||||
|
// Convert RGB to BGR
|
||||||
|
cv::cvtColor(img, dst_image, cv::COLOR_RGB2BGR);
|
||||||
|
img = dst_image;
|
||||||
|
} else if (!is_color) {
|
||||||
|
tools::logger()->warn("Unsupported pixel type: {:#x}. Camera may be outputting already converted format. Using raw image.", pixel_type);
|
||||||
|
// If pixel format is not in the map, the image might already be in the desired format
|
||||||
|
img = img;
|
||||||
|
}
|
||||||
|
|
||||||
queue_.push({img, timestamp});
|
queue_.push({img, timestamp});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user