Open-CV - 未正确加载 [英] Open-CV - Not loading correctly

查看:692
本文介绍了Open-CV - 未正确加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ubuntu 14.04并且我正在尝试编译此代码,但无论如何我都会遇到这些错误,我认为它与包含OpenCV库有关,但我不确定。任何人都可以帮我吗?
错误:

I'm using Ubuntu 14.04 and I'm trying to compile this code, but I get these errors no matter what, I believe it has something to do with including the OpenCV library, but I'm not sure. Could anyone help me out? Errors:


main.cc:66:37:错误:'CV_RETR_EXTERNAL'未在此范围内声明

main.cc:66:37: error: ‘CV_RETR_EXTERNAL’ was not declared in this scope

main.cc:66:55:错误:'CV_CHAIN_APPROX_NONE'未在此范围内声明

main.cc:66:55: error: ‘CV_CHAIN_APPROX_NONE’ was not declared in this scope

main.cc: 81:28:错误:'CV_BGR2GRAY'未在此范围内声明

main.cc:81:28: error: ‘CV_BGR2GRAY’ was not declared in this scope

代码(对不起格式化,我只是可以' t得到这个权利):

The Code(sorry for the formatting, I just can't get this right):

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <tesseract/baseapi.h>
#include <iostream>
void rgb2cmyk(cv::Mat& src, std::vector<cv::Mat>& cmyk)
{
CV_Assert(src.type() == CV_8UC3);

cmyk.clear();
for (int i = 0; i < 4; ++i)
    cmyk.push_back(cv::Mat(src.size(), CV_32F));

for (int i = 0; i < src.rows; ++i)
{
    for (int j = 0; j < src.cols; ++j)
    {
        cv::Vec3b p = src.at<cv::Vec3b>(i,j);

        float r = p[2] / 255.;
        float g = p[1] / 255.;
        float b = p[0] / 255.;
        float k = (1 - std::max(std::max(r,g),b));

        cmyk[0].at<float>(i,j) = (1 - r - k) / (1 - k); 
        cmyk[1].at<float>(i,j) = (1 - g - k) / (1 - k);
        cmyk[2].at<float>(i,j) = (1 - b - k) / (1 - k);
        cmyk[3].at<float>(i,j) = k;
    }
}
}

int main()
{
cv::Mat im0 = cv::imread("scratchcard.png");
if (!im0.data)
    return -1;

std::vector<cv::Mat> cmyk;
rgb2cmyk(im0, cmyk);

cv::Mat im1;
im1 = cmyk[3].mul(1 - cmyk[1]) > 0.25;

cv::Mat im2;
im1.convertTo(im2, CV_8U);

std::vector<std::vector<cv::Point> > contours;
cv::findContours(im2, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

double max_area = 0;
int max_idx = 0;
for (int i = 0; i < contours.size(); i++)
{
    double area = cv::contourArea(contours[i]);
    max_idx  = area > max_area ? i : max_idx;
    max_area = area > max_area ? area : max_area;
}

im2.setTo(cv::Scalar(0));
cv::drawContours(im2, contours, max_idx, cv::Scalar(255), -1);

cv::Mat im3;
cv::cvtColor(im0, im3, CV_BGR2GRAY);
im3 = ((255 - im3) & im2) > 200;

cv::Mat dst = im3.clone();
cv::findContours(dst.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
for (int i = 0; i < contours.size(); i++)
{
    if (cv::contourArea(contours[i]) < 100)
        cv::drawContours(dst, contours, i, cv::Scalar(0), -1);
}

tesseract::TessBaseAPI tess;
tess.Init(NULL, "eng", tesseract::OEM_DEFAULT);
tess.SetVariable("tessedit_char_whitelist", "0123456789");
tess.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);
tess.SetImage((uchar*)dst.data, dst.cols, dst.rows, 1, dst.cols);

char* out = tess.GetUTF8Text();
std::cout << out << std::endl;

cv::imshow("src", im0);
cv::imshow("dst", dst);
cv::waitKey();
return 0;
}

更新:使用cv ::whatever修复了CV_RETR_EXTERNAL和CV_CHAIN_APPROX_NONE错误。
但是,CV_BGR2GRAY错误仍然存​​在,如果更改为cv :: COLOR_BGR2GRAY,则整个代码会突出显示为错误。任何人都有线索?

UPDATE: CV_RETR_EXTERNAL and CV_CHAIN_APPROX_NONE errors were fixed by using cv::"whatever". However, CV_BGR2GRAY error persists, if changed to cv::COLOR_BGR2GRAY the whole code gets highlighted as buggy. Anyone has a clue?

推荐答案

看来,你(不小心)使用3.0(主)opencv分支。

it seems, you are (accidentally) using the 3.0(master) opencv branch.

很多常量已经改变了,就像大多数CV_前缀改为cv :: namespace,
CV_BGR2GRAY现在是cv :: COLOR_BGR2GRAY等。

a lot of constants have changed there, like most of the CV_ prefixes were changed to cv:: namespace, CV_BGR2GRAY is now cv::COLOR_BGR2GRAY, etc.

所有模块标题都有一个,比如opencv2 / imgproc.hpp。

also all module headers went one up, like opencv2/imgproc.hpp .

如果你从中得到了代码github repo,想要使用2.4.9分支,

if you got the code from the github repo, and want to use the 2.4.9 branch instead,

git checkout 2.4

(在opencv文件夹中)将带您到那里。 ofc你将不得不重新运行cmake并重新编译

(in the opencv folder) will take you there. ofc you will have to rerun cmake and recompile

这篇关于Open-CV - 未正确加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆