0

I am learning opencv in c++ but visual studio (2017 community) cant recognize the enum COLOR_BGR2GRAY but it recognizes other functions of opencv.

here is the source code:

#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***
}

Any idea why it does recognize the functions but not COLOR_BGR2GRAY enum?

Guy Shilman
  • 45
  • 12
  • 1
    Please, proof-read your post, and fix the title which doesn't really make sense (and doesn't match what you say in the body of the question). Also, state which specific version of OpenCV you're using -- that's rather relevant. – Dan Mašek Dec 10 '17 at 18:09
  • 1
    The answers to this question might help: https://stackoverflow.com/q/23922620/212870 – Alan Stokes Dec 10 '17 at 18:15
  • 3
    Presumably you're using OpenCV 2.x, in which case the enum is `CV_BGR2GRAY`. https://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#cvtcolor. – alkasm Dec 10 '17 at 19:12
  • @AlexanderReynolds I changed the enum to CV_BGR2GRAY and it worked but the line cvCvtColor(&image, &image_gray, CV_BGR2GRAY); threw an exception: OpenCV Error: Bad argument (Unknown array type) in cv::cvarrToMat, file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\matrix.cpp, line 975 – Guy Shilman Dec 10 '17 at 23:06
  • 1
    @GuyShilman You use the C++ API for all the other functions, so why do you use the C API [`cvCvtColor`](https://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#cvtcolor)? | Also, in order to avoid shooting yourself in the foot in the future, I'd suggest dropping the [`using namespace`](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). – Dan Mašek Dec 10 '17 at 23:12
  • thanks @DanMašek I changed the includes to the c++ library and now everything works perfectly – Guy Shilman Dec 10 '17 at 23:29

1 Answers1

0

Try changing the COLOR_BGR2GRAY to cv::COLOR_BGR2GRAY and check to see if that works