caffe blob and cv::Mat

本文详细解析了Caffe中Blob数据结构与OpenCV中Mat数据结构之间的转换方式,包括它们的行列优先级关系及具体转换公式。特别针对Caffe Blob的行优先特性与OpenCV Mat的数据访问方式进行对比说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

总是忘记caffe blob和mat转化之间的行列优先级关系,索性写个博客.

例如,caffe某个blob的维度是(14,3,216,176),这个表示height=216,width=176,caffe是行优先的,也就是blob.cpu_data得到的指针(dataptr)

dataptr[1]=blob.data_at(0,0,0,1)

更一般的,

dataptr[n*channels*height*width+c*height*width+h*width+w]=blob.data_at(n,c,h,w)

接下来说一说opencv的Mat,假定Mat也是(3,216,176),rows=216=height, cols=176=width,

则mat.at<cv::Vec3f>(x,y)指的是第x行列的数据(例如at(78,40)值得是第78行第40列的数据)

bobac3@reinovo:~/onnx_demo/build$ make [ 50%] Building CXX object CMakeFiles/onnx_demo.dir/src/main.cpp.o /home/bobac3/onnx_demo/src/main.cpp: In function ‘int main(int, char**)’: /home/bobac3/onnx_demo/src/main.cpp:62:24: error:cv::dnn’ has not been declared cv::Mat blob = cv::dnn::blobFromImage(image, 1/255.0, cv::Size(input_w, input_h), cv::Scalar(0,0,0),ture,false); ^~~ /home/bobac3/onnx_demo/src/main.cpp:62:105: error: ‘ture’ was not declared in this scope Image(image, 1/255.0, cv::Size(input_w, input_h), cv::Scalar(0,0,0),ture,false); ^~~~ /home/bobac3/onnx_demo/src/main.cpp:62:105: note: suggested alternative: ‘time’ Image(image, 1/255.0, cv::Size(input_w, input_h), cv::Scalar(0,0,0),ture,false); ^~~~ time /home/bobac3/onnx_demo/src/main.cpp:123:5: error:cv::dnn’ has not been declared cv::dnn::NMSBoxes(boxes, confidences, 0.25, 0.45, indexes); ^~~ /home/bobac3/onnx_demo/src/main.cpp:135:33: error: ‘start’ was not declared in this scope float t = (cv::getTickCount() - start) / static_cast<float>(cv::getTickFrequency()); ^~~~~ /home/bobac3/onnx_demo/src/main.cpp:135:33: note: suggested alternative: ‘sqrt’ float t = (cv::getTickCount() - start) / static_cast<float>(cv::getTickFrequency()); ^~~~~ sqrt CMakeFiles/onnx_demo.dir/build.make:62: recipe for target 'CMakeFiles/onnx_demo.dir/src/main.cpp.o' failed make[2]: *** [CMakeFiles/onnx_demo.dir/src/main.cpp.o] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/onnx_demo.dir/all' failed make[1]: *** [CMakeFiles/onnx_demo.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2 bobac3@reinovo:~/onn
08-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值