我一直在关注 Caffe MINST example并尝试使用 C++ 部署训练模型的测试,我使用 OpenCV 读取图像。在示例中,他们提到了他们如何针对训练和测试图像
scale the incoming pixels so that they are in the range [0,1). Why 0.00390625? It is 1 divided by 256.
我听说 Caffe 中有一个 DataTransformer 类可以用来缩放图像,但是如果我将 OpenCV Mat 对象中的每个像素乘以 0.00390625 是否会得到相同的结果?
最佳答案
这个想法是对的。但请记住在缩放之前将您的 OpenCV Mats 转换为 float 或 double 类型。
类似于:
cv::Mat mat; // assume this is one of your images (grayscale)
/* convert it to float */
mat.convertTo(mat, CV_32FC1); // use CV_32FC3 for color images
/* scaling here */
mat = mat * 0.00390625;
更新 #1:转换和缩放也可以简单地在一行中完成,即
cv::Mat mat; // assume this is one of your images (grayscale)
/* convert and scale here */
mat.convertTo(mat, CV_32FC1, 0.00390625);
关于opencv - 为 Caffe 缩放 OpenCV Mat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32216638/