c++ - opencv:对 "Mat"的调用不明确

标签 c++ opencv computer-vision

我尝试使用opencv计算HoG描述符,但是报错call to "Mat" is ambiguous被提出。

我在Error: Mat is ambiguous when using OpenCV下看到了答案

而且我不知道我的包含是否正确。

我的 opencv 包括:

#include <opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv/cv.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <opencv2/ml/ml.hpp>
#include <string>

using namespace std;
using namespace cv;
using namespace cv::ml;

代码如下:

for (int j = 0; j < original[i]; j++) {
        cv::Mat train_original;
        train_original = cv::imread(original_path + std::to_string(j) + ".jpg", 1);

        cv::resize(train_original, train_resize_image, cv::Size(128, 128), 0, 0, CV_INTER_LINEAR);
        // 计算HOG descriptor
        cv::HOGDescriptor hog(cv::Size(128, 128), cv::Size(64, 64), cv::Size(16, 16), cv::Size(8, 8), 9);
        hog.compute(train_resize_image,train_descriptor);
        cv::Mat descriptor_mat(cv::Mat(train_descriptor).t());
        train_descriptors.push_back(descriptor_mat);
    }

哪里train_descriptor类型为 std::vector<float>

行中出现错误

cv::Mat descriptor_mat(cv::Mat(train_descriptor).t());

任何帮助将不胜感激!谢谢!

最佳答案

您应该更改以下行:

cv::Mat descriptor_mat(cv::Mat(train_descriptor).t());

cv::Mat descriptor_mat = cv::Mat(train_descriptor).t();

因为 Mat operator = 可以处理 MatExpr 对象,而 Mat 构造函数不能(检查 OpenCV documentation )。但要小心使用此方法,因为它不会复制数据并共享它(如指针)。基本上,如果您想复制数据,您可以执行以下操作:

 cv::Mat descriptor_mat;
 cv::transpose(cv::Mat(train_descriptor),descriptor_mat);

关于c++ - opencv:对 "Mat"的调用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48166778/

相关文章:

python - 高斯滤波器后合并接近的对象

python - 如何设置 Gamma 校正的最佳值

python - 如何在opencv(阈值)中改变轮廓形成的区域

c++ - 如何创建特定(R,G,B)颜色的openCV图像并获取该颜色名称?

azure - 使用不记名 token 授权 Azure 请求?

image - 类型错误:参数 'array' 的预期 Ptr<cv::UMat>

c++ - 如何导出模板函数?或者这种情况的首选方法是什么?

c++ - KMP算法的时间复杂度

c++ - 在 Qt 中从 QByteArray 加载 QPixmap?

c++ - 单引号在 C++ 中用于多个字符时有什么作用?