I encountered a strange issue in C++ and OpenCV2. The following code does not print "I ran!
":
#include <iostream>
#include <opencv2/opencv.hpp>
// Opens image as grayscale and saves it to save_dir
int grayscale_file(const cv::String &file_dir, const std::string &save_dir){
cv::Mat fi = cv::imread(file_dir, cv::ImreadModes::IMREAD_GRAYSCALE);// Loads image as grayscale
return cv::imwrite(save_dir, fi);
}
int main(int argc, char* argv[]){
std::cout << "I ran!" << std::endl;
return 0;
}
However when I remove the code inside grayscale_file
, it prints "I ran!
":
#include <iostream>
#include <opencv2/opencv.hpp>
// Opens image as grayscale and saves it to save_dir
int grayscale_file(const cv::String &file_dir, const std::string &save_dir){
return 0;
}
int main(int argc, char* argv[]){
std::cout << "I ran!" << std::endl;
return 0;
}
Why does the first piece of code prevent "I ran!
" from being printed to the terminal, whereas the second piece of code doesnt?
Edit: Commenting some things out lead me to the issue of the cv::imread
function. Removing the line that uses this lets the program run. I found a post here that explains it pretty well. I'll find a debug library instead of the release that I think I was using.