opencv4版本与旧版本代码的若干冲突

(1)

#include <cv.h>

报错:无法找到cv.h

解决方法:

//替换为
#include <opencv2/imgproc.hpp>

(2)

Mat imgSrc;
CvMat tempImg = imgSrc;

报错:不存在用户定义的cv::Mat到CvMat的转换

找到CvMat的定义:

//在types_c.h文件中
typedef struct CvMat
{
    int type;
    int step;

    /* for internal use only */
    int* refcount;
    int hdr_refcount;

    union
    {
        uchar* ptr;
        short* s;
        int* i;
        float* fl;
        double* db;
    } data;

#ifdef __cplusplus
    union
    {
        int rows;
        int height;
    };

    union
    {
        int cols;
        int width;
    };
#else
    int rows;
    int cols;
#endif

#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
    CvMat() {}
    CvMat(const cv::Mat& m) { *this = cvMat(m); }
#endif
}
CvMat;

其中cv::Mat到CvMat的转换函数如下:

CvMat(const cv::Mat& m) { *this = cvMat(m);

解决办法:

CvMat tempImg = cvMat(imgSrc);

(3)

cvtColor(m_SrcImg, m_SrcImg, cv_BGR2GRAY);

cv_BGR2GRAY未定义标识符

解决方法:

cvtColor(m_SrcImg, m_SrcImg, COLOR_BGR2GRAY);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值