Home > database >  A loading question when I use OpenCV load a picture
A loading question when I use OpenCV load a picture

Time:02-05

When I use the complier it gives me the error code :

    OpenCV(4.2.0) Error: Assertion failed (!_src.empty()) in cv::cvtColor, 
    file C:\build\master_winpack-build-win64-vc14\opencv\modules\imgproc\src\color.cpp, line 182

I located where the problem occurred in this part :

    auto texture_path = "hmap.jpg";
    Texture texture = Texture(obj_path   texture_path);
    r.set_texture(texture);

And the obj_path :

    std::string obj_path = "../models/spot/";

When I creat the texture I use the function :

    Texture(const std::string& name)
        {
            image_data = cv::imread(name);
            cv::cvtColor(image_data, image_data, cv::COLOR_RGB2BGR);
            width = image_data.cols;
            height = image_data.rows;
        }

The problem happend in 4th line cv::cvtColor(image_data, image_data, cv::COLOR_RGB2BGR);

I have checked the path, my file structure is like this :

enter image description here

I don't konw why the problrm happend.

CodePudding user response:

obj_path texture_path is "../models/spothmap.jpg"

CodePudding user response:

I find change the obj_path to Assigment3/Code/models/spot/ can solve this question. The problem is taht I made a mistake on the default working directory when I run my project on my IDE.

CodePudding user response:

your Code and all file directories should be at the same location. It's major problem to install in the terminal. Please check the first file directory.

  •  Tags:  
  • Related