欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

NumCpp使用示例二与std::vector及cv::Mat之间的相互转换

时间:2023-06-05

以读取图片为例,实现NumCPP数组与std::vector、std::array、cv::Mat等数组之间的相互类型转换

一、std::array转NdArray

std::array a_std = { 1, 2, 3 }; //参数false表示拷贝地址(浅拷贝),而非拷贝值(深拷贝) auto a_np = nc::NdArray(a_std, false); //修改a_std的值 a_std[0] = -0.4; // 输出数组 std::cout << a_std[0] << " , " << a_std[1] << " , " << a_std[2] << std::endl; a_np.print();

2、cv::Mat转std::vector

string fname = "C:/AI_Dataset/whdld/WHDLD/label/wh0034.png"; cv::Mat image = cv::imread(fname, -1);//, cv::ImreadModes::IMREAD_COLOR //printf_s("%d,CV_8UC3:%dn",image.type(), CV_8UC3); //把三通道mat进行分割 vector BGR; cv::split(image, BGR); //把内存不连续的数组进行拷贝,使其连续 if (!image.isContinuous()) { image = image.clone(); } printf_s("BGR&#x

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。