【问题标题】:visual studio recognizes opencv functions but not COLOR_BGR2GRAY enumVisual Studio 可以识别 opencv 函数,但不能识别 COLOR_BGR2GRAY 枚举
【发布时间】:2017-12-10 17:56:50
【问题描述】:

我正在学习 c++ 中的 opencv,但 Visual Studio(2017 社区)无法识别枚举 COLOR_BGR2GRAY,但它可以识别 opencv 的其他功能。

这里是源代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <Windows.h>

using namespace cv;
using namespace std;

void drawSquares(Mat image);

int main(int argc, char** argv)
{
    if (argc != 2)
    {
        cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }

    Mat image;
    image = imread(argv[1], IMREAD_COLOR); // Read the file

    if (!image.data) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl;
        return -1;
    }

    namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
    imshow("Display window", image); // Show our image inside it.



    waitKey(0); // Wait for a keystroke in the window
    return 0;
}

void drawSquares(Mat image)
{
    Mat image_gray;
    cvCvtColor(&image, &image_gray, COLOR_BGR2GRAY); //***it doest recognize this enum in this line***
}

知道为什么它能识别函数但不能识别 COLOR_BGR2GRAY 枚举吗?

【问题讨论】:

  • 请校对您的帖子,并修正没有意义的标题(并且与您在问题正文中所说的不符)。另外,请说明您正在使用哪个特定版本的 OpenCV - 这很相关。
  • 这个问题的答案可能会有所帮助:stackoverflow.com/q/23922620/212870
  • 假设您使用的是 OpenCV 2.x,在这种情况下,枚举为 CV_BGR2GRAYdocs.opencv.org/2.4/modules/imgproc/doc/….
  • @AlexanderReynolds 我将枚举更改为 CV_BGR2GRAY 并且它有效,但是 cvCvtColor(&image, &image_gray, CV_BGR2GRAY);抛出异常:OpenCV 错误:cv::cvarrToMat 中的参数错误(未知数组类型),文件 C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\matrix.cpp,第 975 行跨度>
  • @GuyShilman 您对所有其他功能都使用 C++ API,那么为什么要使用 C API cvCvtColor? |另外,为了避免将来在自己的脚下开枪,我建议放弃using namespace

标签: c++ opencv


【解决方案1】:

尝试将COLOR_BGR2GRAY 更改为cv::COLOR_BGR2GRAY 并检查是否有效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-06
    • 2019-01-08
    • 1970-01-01
    • 2022-01-06
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    相关资源
    最近更新 更多