mingw32-make undefined reference to `cv::imread(cv::String const&, int)' OPENCV - c++

So I have OpenCV libraries downloaded from here
https://sourceforge.net/projects/opencvlibrary/files/3.4.6/opencv-3.4.6-vc14_vc15.exe/download
CMake gui with cmakelist.txt like this
cmake_minimum_required(VERSION 2.8)
project(Display)
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library
status:") message(STATUS " config:
${OpenCV_DIR}") message(STATUS "
version: ${OpenCV_VERSION}")
message(STATUS " libraries:
${OpenCV_LIBS}") message(STATUS "
include path: ${OpenCV_INCLUDE_DIRS}")
add_executable(Display
DisplayImage.cpp)
target_link_libraries(Display
${OpenCV_LIBS})
and have a simple cpp like this
#include <stdio.h>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv )
{
// cout << "You have entered " << argc
// << " arguments:" << "\n";
// for (int i = 0; i < argc; ++i)
// cout << argv[i] << "\n";
// cout << "a" << argv[1];
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
printf("Hello World!");
return 0;
}
already configure it with cmake-gui and this shows up
OpenCV library status:
config: D:/opencv/build/x64/vc15/lib
version: 3.4.6
libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_world
include path: D:/opencv/build/include;D:/opencv/build/include/opencv;D:/opencv/build/include/opencv2
Configuring done Generating done
seems good right ? and then on the build directory from command prompt, i typed mingw32-make
and this shows up
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text+0x72):
undefined reference to
cv::imread(cv::String const&, int)'
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text+0xe3):
undefined reference to
cv::namedWindow(cv::String const&,
int)'
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text+0x129):
undefined reference to
cv::imshow(cv::String const&,
cv::_InputArray const&)'
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text+0x149):
undefined reference to
cv::waitKey(int)'
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text$_ZN2cv6StringC1EPKc[__ZN2cv6StringC1EPKc]+0x42):
undefined reference to
cv::String::allocate(unsigned int)'
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text$_ZN2cv6StringD1Ev[__ZN2cv6StringD1Ev]+0xf):
undefined reference to
cv::String::deallocate()'
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text$ZN2cv6StringaSERKS0[__ZN2cv6StringaSERKS0_]+0x1c):
undefined reference to
cv::String::deallocate()'
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to
cv::fastFree(void*)'
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x40):
undefined reference to
cv::Mat::deallocate()'
CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text$_ZN2cv3MataSEOS0_[__ZN2cv3MataSEOS0_]+0xb4):
undefined reference to
cv::fastFree(void*)' collect2.exe:
error: ld returned 1 exit status
mingw32-make[2]: *
[CMakeFiles\Display.dir\build.make:104:
Display.exe] Error 1 mingw32-make[1]:
* [CMakeFiles\Makefile2:72: CMakeFiles/Display.dir/all] Error 2
mingw32-make: *** [Makefile:83: all]
Error 2
how do i fix this ? or is it because that i use the library straight from the website ?
i also try something like putting a wrong parameter on the imread function and then type mingw32-make and it did tell me that i use a wrong parameter. If they know i used the wrong parameter, then why they can't tell what is imread for (or why is it undefined reference ? ) ? I'm using windows.
I'm very new to these libraries, mingw, and cmake, so i'm sorry if my question is stupid.
this question is not duplicate because, i use windows and mingw32-make, everyone that asks this question did not use that and the question is in a different situation than mine.

Related

Use SDL2 with CLion 2020

I can't seem to link SDL2 correctly. I am using CLion with MinGW. My CMakeLists.txt looks like this currently, but I tried using the FindSDL2 module floating around, though it always said that it could not find the SDL2 library. This is the only way I've found it to stop giving back errors.
cmake_minimum_required(VERSION 3.16)
project(CBeat)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "CC:/Development/SDL2_MinGW_32bit/lib/cmake/SDL2")
set(SDL2_DIR C:/Mingw)
set(CMAKE_CXX_STANDARD 14)
set(SDL2_LIB_DIR ${SDL2_DIR}/lib)
include_directories(${SDL2_DIR}/include)
add_executable(CBeat main.cpp)
target_link_libraries(CBeat ${SDL2_LIB_DIR}/libSDL2.dll.a ${SDL2_LIB_DIR}/libSDL2main.a ${SDL2_LIB_DIR}/libSDL2.a -mwindows -lmingw32 -lSDL2main -lSDL2)
add_definitions(-DSDL_MAIN_HANDLED)
Now, the main.cpp looks like this, CLion shows no errors and actually is able to give me suggestions and information in each function, but when running it marks various functions as undefined. I attach evidence. I am so desperate right now, I've been trying to figure out this for days now and nothing seems to work!
#include <iostream>
#include <SDL2/SDL.h>
using namespace std;
const int SWIDTH=640, SHEIGHT=420;
int main( int argc, char* args[] ){
SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;
if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
{
cout<< "SDL could not initialize! SDL_Error:" << SDL_GetError << endl;
}
else
{
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SWIDTH, SHEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
cout << "Window could not be created! SDL_Error: " << SDL_GetError << endl;
}
else
{
screenSurface = SDL_GetWindowSurface(window);
SDL_FillRect(screenSurface, NULL,SDL_MapRGB(screenSurface->format, 0xFF,0xFF,0xFF));
SDL_UpdateWindowSurface( window );
SDL_Delay( 2000 );
}
SDL_DestroyWindow( window );
SDL_Quit();
return 0;
}
}
CLion trying to be useful
And these are the errors it gives back:
[ 50%] Linking CXX executable CBeat.exe
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: CMakeFiles\CBeat.dir/objects.a(main.cpp.obj): in function `main':
C:/Users/yello/CLionProjects/CBeat/main.cpp:12: undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/yello/CLionProjects/CBeat/main.cpp:18: undefined reference to `SDL_CreateWindow'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/yello/CLionProjects/CBeat/main.cpp:25: undefined reference to `SDL_GetWindowSurface'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/yello/CLionProjects/CBeat/main.cpp:26: undefined reference to `SDL_MapRGB'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/yello/CLionProjects/CBeat/main.cpp:26: undefined reference to `SDL_FillRect'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/yello/CLionProjects/CBeat/main.cpp:27: undefined reference to `SDL_UpdateWindowSurface'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/yello/CLionProjects/CBeat/main.cpp:28: undefined reference to `SDL_Delay'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/yello/CLionProjects/CBeat/main.cpp:30: undefined reference to `SDL_DestroyWindow'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/yello/CLionProjects/CBeat/main.cpp:31: undefined reference to `SDL_Quit'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\CBeat.dir\build.make:88: recipe for target 'CBeat.exe' failed
CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/CBeat.dir/all' failed
mingw32-make.exe[3]: *** [CBeat.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/CBeat.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/CBeat.dir/rule] Error 2
mingw32-make.exe: *** [CBeat] Error 2
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/CBeat.dir/rule' failed
Makefile:117: recipe for target 'CBeat' failed

Linking error while compiling sample of OpenCV

I tried to compile simple program using OpenCV 4.11 and current version of Mingw on Windows 7. I downloaded binaries for OpenCV from https://github.com/huihut/OpenCV-MinGW-Build. I tried to compile it using command:
"g++ main.cpp -std=c++11 -I F:\cpp_tools\libs\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\include -L F:\cpp_tools\libs\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\lib -lopencv_core411.dll -lopencv_imgcodecs411.dll -lopencv_imgproc411.dll -lopencv_highgui411.dll -o myprog.exe"
and i got linker error:
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0xa0): undefined re
ference to cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, int)'
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0x13e): undefined r
eference tocv::namedWindow(std::__cxx11::basic_string, std::allocator > const&, int)'
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0x19f): undefined r
eference to cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, cv::_InputArray const&)'
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0x1c9): undefined r
eference tocv::waitKey(int)'
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text$_ZN2cv3MatD1Ev[__ZN
2cv3MatD1Ev]+0x2d): undefined reference to cv::fastFree(void*)'
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text$_ZN2cv3Mat7releaseE
v[__ZN2cv3Mat7releaseEv]+0x40): undefined reference tocv::Mat::deallocate()'
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text$ZN2cv3MataSEOS0[_
ZN2cv3MataSEOS0]+0xb4): undefined reference to `cv::fastFree(void*)'
collect2.exe: error: ld returned 1 exit status
I read alot of similar problems but any of it didn't solved my problem.
Source code:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
String imageName( "../data/HappyFish.jpg" ); // by default
if( argc > 1)
{
imageName = argv[1];
}
Mat image;
image = imread( imageName, IMREAD_COLOR ); // Read the file
if( image.empty() ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", image );
waitKey(0); // Wait for a keystroke in the window
return 0;
}
Shouldn't it be
g++ main.cpp -std=c++11 -I F:\cpp_tools\libs\OpenCV-MinGW-
Build-OpenCV-4.1.1-x64\include -L F:\cpp_tools\libs\OpenCV-
MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\lib
-llibopencv_core411 -llibopencv_imgcodecs411
-llibopencv_imgproc411 -llibopencv_highgui411 -o
myprog.exe
with -llibopencv instead of -lopencv?
Have you tried the help Running a C++ program with OpenCV 3.4.1 using MinGW-w64 g++ in Visual Studio Code on Windows 10 x64 mentioned on GitHub?

OpenCV: undefined reference to `cv::namedWindow(cv::String const&, int)'

UPDATE: The code compiles successfully on another computer. So the problem is not with the code itself but with the way I have the dependencies installed.
If I have omitted any necessary information, please let me know. The full code can be found here.
The following code compiles and runs perfectly fine on Ubuntu 14.04 with OpenCV 3.2.0 freshly installed from SourceForge using these instructions:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitkey(0);
return 0;
}
Using the following CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
The following code fails to compile.
lane_finder.h
#ifndef Lane_Finder_h
#define Lane_Finder_h
#include <stdio.h>
#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/image_encodings.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/opencv.hpp>
class LaneFinder
{ *snip* }
#endif
lane_finder.cpp:
#include "lane_finder.h"
sensor_msgs::CompressedImage LaneFinder::findLanes(const sensor_msgs::Image& msg) {
*snip*
frame = in_msg->image;
cv::namedWindow("Display Image", cv::WINDOW_AUTOSIZE );
cv::imshow("Display Image", frame);
*snip*
}
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(lane_finding)
find_package(catkin REQUIRED COMPONENTS roscpp cv_bridge sensor_msgs)
find_package(OpenCV REQUIRED)
catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
add_executable(lane_finder src/lane_finder.cpp src/main.cpp)
target_link_libraries(lane_finder
${catkin_LIBRARIES}
${OpenCV_LIBS}
)
Compile Errors:
CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `LaneFinder::findLanes(sensor_msgs::Image_<std::allocator<void> > const&)':
lane_finder.cpp:(.text+0x36c): undefined reference to `cv::namedWindow(cv::String const&, int)'
lane_finder.cpp:(.text+0x3c1): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `cv::String::String(char const*)':
lane_finder.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4f): undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `cv::String::~String()':
lane_finder.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `cv::String::operator=(cv::String const&)':
lane_finder.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
I cannot for the life of me figure out why one runs perfectly and the other fails. I suspect that I have linked something improperly, since this is my first time attempting to compile using a header file I wrote myself. If you believe that I have omitted something important in attempting to keep this readable, I have included a link to the github repo containing the full code at the beginning of this post.
Thank you all so much.
You should add this option:
pkg-config opencv --cflags --libs
My pltform:
Win10 64bit
QT58(mingw53)
after installing opencv 3.30, I write code:
//main.cc
#include <iostream>
#include <QDir>
#include <qdebug>
#include "opencv2/opencv.hpp"
using namespace std;
int main()
{
qDebug()<< QDir::currentPath();
cv::Mat image = cv::imread("1.jpg",1);
std::cout << image.cols << " " << image.rows << std::endl;
if(image.data == 0){
cout << "No Image" <<endl;
}
else{
cout << "Image" << endl;
}
cv::namedWindow("My Image");
cv::imshow("My Image", image)
system("pause");
return 0;
}
I get the error, like this:
release/main.o:main.cpp:(.text.startup+0x170): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
collect2.exe: error: ld returned 1 exit status
I dont know why, but other functions work well,expect imshow(). And I did add the LIBS:
//qt.pro
INCLUDEPATH += D:\opencv\build\mingw\include
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_highgui330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_calib3d330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_dnn330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_features2d330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_flann330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_imgcodecs330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_imgproc330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_ml330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_objdetect330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_photo330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_shape330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_stitching330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_superres330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_video330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_videoio330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_videostab330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\opencv_ffmpeg330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_core330.dll
cv_bridge depends on OpenCV 2.4. Change the CMakeLists.txt to specify:
find_package(OpenCV 2 REQUIRED)

"Function not declared in this scope" Error in compiling openCV code

I'm trying to write some code which uses openCV functions. I started by taking some of the example code available in the documentation:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1]); // 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", CV_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;
}
When I try to build it in Eclipse-CDT, I get this:
**** Build of configuration Debug for project openCV1 ****
make all
Building target: openCV1
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "openCV1" ./src/displayImage.o
./src/displayImage.o: In function `main':
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:25: undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:33: undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:34: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:34: undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:36: undefined reference to `cv::waitKey(int)'
./src/displayImage.o: In function `~Mat':
/usr/local/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
./src/displayImage.o: In function `cv::Mat::operator=(cv::Mat const&)':
/usr/local/include/opencv2/core/mat.hpp:298: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
./src/displayImage.o: In function `cv::Mat::release()':
/usr/local/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
make: *** [openCV1] Error 1
**** Build Finished ****
The same code, when I build with g++ (g++ -o displayImageInput displayImageInput.cpppkg-config opencv --cflags --libs) works.
I then changed the code to make the image greyscale,
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1]); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
Mat grey;
cvtColor(image, grey, CV_BGR2GRAY);
namedWindow("image", CV_WINDOW_AUTOSIZE);
imshow("image", grey);
waitKey(); // Wait for a keystroke in the window
return 0;
}
It gave the following error when building with g++:
dispImgSobel.cpp: In function ‘int main(int, char**)’:
dispImgSobel.cpp:34:27: error: ‘CV_BGR2GRAY’ was not declared in this scope
dispImgSobel.cpp:34:38: error: ‘cvtColor’ was not declared in this scope
I need help with two things, How to get it working in Eclipse, and second, how to resolve this scope error, for this and future use cases.
the first err is a linker problem. you did not link against opencv_core.a and opencv_highgui.a
rule of thumb: for every module header you include, you'll need to link the appropriate library.
the 2nd is a compiler problem, you forgot a header, #include <opencv2/imgproc/imgproc.hpp>
and, ofc. need to link opencv_imgproc
Make sure that everything in the output of pkg-config opencv --cflags --libs is in your search path for the linker.
There's also a pkg-config add-on for Eclipse which will allow you to put the exact string above in directly rather than manually adding each item of the output.

Installing OpenCV2.4.1 on windows 7 x64 - Mingw & codeblocks

Installing OpenCV2.4.1 on windows 7 x64 - Mingw & codeblocks
Hi,
I followed this tutorial
Getting started with OpenCV 2.4 and MinGW on Windows 7
I configured the same except instead of x86, i put x64.
This is the example
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat im = imread(argc == 2 ? argv[1] : "lena.jpg", 1);
if (im.empty())
{
cout << "Cannot open image!" << endl;
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
when i compile main.cpp
C:\Users\rgap\Desktop>g++ -I"C:\opencv\build\include" -L"C:\opencv\build\x64\mingw\lib" main.cpp -lope
ncv_core241 -lopencv_highgui241 -o main
I get the following error
C:\Users\rgap\AppData\Local\Temp\ccDgmPAT.o:main.cpp:(.text+0x62): undefined reference to `cv::imread(
std::string const&, int)'
C:\Users\rgap\AppData\Local\Temp\ccDgmPAT.o:main.cpp:(.text+0xc7): undefined reference to `cv::_InputA
rray::_InputArray(cv::Mat const&)'
C:\Users\rgap\AppData\Local\Temp\ccDgmPAT.o:main.cpp:(.text+0xfe): undefined reference to `cv::imshow(
std::string const&, cv::_InputArray const&)'
C:\Users\rgap\AppData\Local\Temp\ccDgmPAT.o:main.cpp:(.text+0x120): undefined reference to `cv::waitKe
y(int)'
C:\Users\rgap\AppData\Local\Temp\ccDgmPAT.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x2b): und
efined reference to `cv::fastFree(void*)'
C:\Users\rgap\AppData\Local\Temp\ccDgmPAT.o:main.cpp:(.text$_ZN2cv3Mat7releaseEv[cv::Mat::release()]+0
x3c): undefined reference to `cv::Mat::deallocate()'
collect2: ld devolvió el estado de salida 1
Is this a bug? :(
thanks :)