1.工业上多数视觉开发都是用halcon开发的,halcon本身也有自己的深度学习网络,至于halcon如果不使用本身的深度学习,使用其他网络导出的onnx模型怎样配合使用?本文基于yolov8写一个列子。
2。创建输入数据的转换代码
#region 创建输入数据
HTuple height_, width_, channel_image_;
HOperatorSet.GetImageSize(_image,
out width_,
out height_);
HOperatorSet.CountChannels(_image, out channel_image_);
int by_count_ = 640 * 640 * 3;
byte[] bytes = new byte[by_count_];
int by_index_ = 0;
for (int r_ = 0; r_ < 640; r_++)
{
for (int c_ = 0; c_ < 640; c_++)
{
if (r_ < height_ && c_ < width_)
{
HTuple gval_;
HOperatorSet.GetGrayval(_image, r_, c_, out gval_);
bytes[by_index_] = (byte)gval_[0].I;
bytes[by_index_+640*640] = (byte)gval_[1].I;
bytes[by_index_+640*640*2] = (byte)gval_[2].I;
by_index_++;
}
else
{
bytes[by_index_] = (byte)0;
bytes[by_index_ + 640 * 640] = (byte)0;
bytes[by_index_ + 640 * 640 * 2] = (byte)0;
by_index_++;
}
}
}
int leng_ = bytes.GetLength(0);
long[] input_shape_ = { 1, 3, 640, 640 };
float[] input_data_ = new float[leng_];
for (int i = 0; i < leng_; i++)
{
input_data_[i] = ((float)bytes[i]) / 255;//初拟255归一化
}
var input_ort_value_ = OrtValue.CreateTensorValueFromMemory(input_data_, input_shape_);
var inputs1_ = new Dictionary<string, OrtValue> { { "images", input_ort_value_ } };
#endregion
3.软件界面
4.b站视频地址:
https://www.bilibili.com/video/BV1SoKkeREXR/?spm_id_from=333.999.0.0
5.源代码地址:
https://gf.bilibili.com/item/detail/1106284118?noTitleBar=1&from=mall-up_itemDetail&msource=comments_1980214179&track_id=na_1980214179_BV1SoKkeREXR_B