I am having issues running this code:
// CannyStill.cpp
//#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include<iostream>
#include<conio.h>
int main() {
cv::Mat imgOriginal; // input image
cv::Mat imgGrayscale; // grayscale of input image
cv::Mat imgBlurred; // intermediate blured image
cv::Mat imgCanny; // Canny edge image
imgOriginal = cv::imread("image.png"); // open image
if (imgOriginal.empty()) { // if unable to open image
std::cout << "error: image not read from file\n\n"; // show error message on command line
_getch(); // may have to modify this line if not using Windows
return(0); // and exit program
}
cv::cvtColor(imgOriginal, imgGrayscale, CV_BGR2GRAY); // convert to grayscale
cv::GaussianBlur(imgGrayscale, // input image
imgBlurred, // output image
cv::Size(5, 5), // smoothing window width and height in pixels
1.5); // sigma value, determines how much the image will be blurred
cv::Canny(imgBlurred, // input image
imgCanny, // output image
82, // low threshold
164); // high threshold
// declare windows
cv::namedWindow("imgOriginal", CV_WINDOW_AUTOSIZE); // note: you can use CV_WINDOW_NORMAL which allows resizing the window
cv::namedWindow("imgCanny", CV_WINDOW_AUTOSIZE); // or CV_WINDOW_AUTOSIZE for a fixed size window matching the resolution of the image
// CV_WINDOW_AUTOSIZE is the default
cv::imshow("imgOriginal", imgOriginal); // show windows
cv::imshow("imgCanny", imgCanny);
cv::waitKey(0); // hold windows open until user presses a key
return(0);
}
My issues seems to come from issues from the include statements. I can one or two of them and I have in all the includes I get:
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x81): undefined reference to `cv::imread(cv::String const&, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0xd4): undefined reference to `std::cout'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0xd9): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x142): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x1e1): undefined reference to `cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x25a): undefined reference to `cv::Canny(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, bool)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x295): undefined reference to `cv::namedWindow(cv::String const&, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x2c6): undefined reference to `cv::namedWindow(cv::String const&, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x30c): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x35c): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x37c): undefined reference to `cv::waitKey(int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x4e3): undefined reference to `std::ios_base::Init::~Init()'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x504): undefined reference to `std::ios_base::Init::Init()'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv6StringC1EPKc[__ZN2cv6StringC1EPKc]+0x42): undefined reference to `cv::String::allocate(unsigned int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv6StringD1Ev[__ZN2cv6StringD1Ev]+0xf): undefined reference to `cv::String::deallocate()'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to `cv::fastFree(void*)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x40): undefined reference to `cv::Mat::deallocate()'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv3MataSEOS0_[__ZN2cv3MataSEOS0_]+0xb4): undefined reference to `cv::fastFree(void*)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.eh_frame$_ZN2cv6StringD1Ev+0x13): undefined reference to `__gxx_personality_v0'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.eh_frame$_ZN2cv3MatD1Ev+0x13): undefined reference to `__gxx_personality_v0'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2.exe: error: ld returned 1 exit status
I have played around with commenting out some and including others and it just leaves an error that cv does not have some of the functions. Which from my understanding of opencv I need all of these libraries.
I am using OpenCV 3.4.1 that I built from the sources using Cmake for MinGW compiler which I am trying to use to compile this.
Any help would be appreciated and if you have any questions I will try to answer them to the best of my ability. Thanks.