以读取图片为例,实现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