Error linking to OpenCV after restructure of code - opencv

I've just reorganised my code (which worked before) and am now getting an error message when I run my executable: The program can't start because opencv_core230d.dll is missing from your computer. The error is accurate, I only have .lib library files for OpenCV, but it worked before and I don't think this should be a problem, should it?
An extract from the cmake file is:
FIND_PACKAGE( OpenCV REQUIRED )
# Define LIBRARY and SRC_FILES to create my library
add_library(${LIBRARY} ${SRC_FILES})
target_link_libraries(${LIBRARY} ${OpenCV_LIBS} )
# Define appName and appFile to create application,
# and link to my library and OpenCV
add_executable(${appName} ${appFile})
target_link_libraries(${appName} ${LIBRARY} ${OpenCV_LIBS})
Am I doing anything obviously wrong, or what else might cause this error?
EDIT: I've now reduced this problem to a minimal example. Inside one directory test I have two files: testApp.cpp and CMakeLists.txt as follows:
testApp.cpp
#include <opencv2/opencv.hpp>
int main(int argc, char* argv[])
{
cv::namedWindow("Test");
cv::waitKey(0);
cv::destroyAllWindows();
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(test)
FIND_PACKAGE( OpenCV REQUIRED )
add_executable(appName testApp.cpp)
target_link_libraries(appName ${OpenCV_LIBS})
message(STATUS "Linking testapp to: ${OpenCV_LIBS}")
With the error as before: opencv_highgui230d.dll is missing.

The problem is that the environment variable PATH does not point to the location where OpenCV's DLLs reside. Search inside OpenCV directories and if you can't find it you'll need to reinstall OpenCV.

Seems this is a common problem which simply needed some more research. To fix, I just added the OpenCV/bin directory to the PATH environmental variable. Still not sure why it was working previously though...

Related

Installing opencv + fatal error: 'opencv2/core.hpp' file not found

I have installed open cv using the official installation process given at:
https://docs.opencv.org/4.5.2/d0/db2/tutorial_macos_install.html
I am doing this on mac and it took ~3 hours for this process. After installation, the installed directory looks like this:
apple#Apples-MacBook-Air.local:~/Learning/openCV/cpp$ pwd
/Users/apple/Learning/openCV/cpp
apple#Apples-MacBook-Air.local:~/Learning/openCV/cpp$ ls
3rdparty CTestTestfile.cmake bin data
opencv_data_config.hpp setup_vars.sh
CMakeCache.txt Makefile cmake_install.cmake doc
opencv_lapack.h test-reports
CMakeDownloadLog.txt OpenCVConfig-version.cmake cmake_uninstall.cmake
include opencv_python_config.cmake tmp
CMakeFiles OpenCVConfig.cmake configured lib
opencv_python_tests.cfg unix-install
CMakeVars.txt OpenCVModules.cmake custom_hal.hpp modules
opencv_tests_config.hpp version_string.tmp
CPackConfig.cmake apps cv_cpu_config.h opencv
python_loader
CPackSourceConfig.cmake basicOp.cpp cvconfig.h opencv2
samples
Now, I am writing a very simple program to test the installation and it looks like that I need to do more things than what I have done so far.
My simple program:
#include<iostream>
#include<opencv2/core.hpp>
int main() {
std::string imagePath = samples.findFile("starry_night.jpg");
cv::Mat imageMatrix = cv::imread(imagePath);
if(imageMatrix.empty()) {
std::cout << "Matrix is empty" << std::endl;
}
}
Compiling this gives error as:
apple#Apples-MacBook-Air.local:~/Learning/openCV/programs$ g++ imageRead.cpp
imageRead.cpp:2:9: fatal error: 'opencv2/core.hpp' file not found
#include<opencv2/core.hpp>
No problem, I can probably understand that due to non-linkage of the open cv libraries.
So, I compiled with:
apple#Apples-MacBook-Air.local:~/Learning/openCV/programs$ g++ imageRead.cpp -I/Users/apple/Learning/openCV/cpp/include -L/Users/apple/Learning/openCV/cpp/lib/
imageRead.cpp:2:9: fatal error: 'opencv2/core.hpp' file not found
#include<opencv2/core.hpp>
And it still give me the same error. Basically, I passed the paths for gcc to consider for linking.
Any suggestions? I can help providing more details on it, if needed.
Did you try #include<opencv2/opencv.hpp> instead of #include<opencv2/core.hpp>?

Undefined symbol using emcmake (emscripten and opencv)

I'm trying to build a minimalist project using OpenCV in the browser.
I've compiled OpenCV on my computer.
Here is the C++ code (josef.cpp):
#include <iostrem>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/opencv.hpp>
int main(int argc, char **argv)
{
printf("Hello here\n");
cv::Mat m;
std::cout << m;
}
Here is the CMakeLists.txt :
cmake_minimum_required(VERSION 2.8)
project( josef )
# Give here the directory in which we have
# the file OpenCVConfig.cmake
set(OpenCV_DIR "/usr/local/lib/cmake/opencv4")
find_package( OpenCV REQUIRED )
add_executable( josef josef.cpp )
target_link_libraries( josef ${OpenCV_LIBS} )
Compiling with
cmake .
make
works perfectly well and provides an executable which produces the expected result:
Hello here
[]
My problem arises when trying with emscripten.
emcmake cmake .
produces lot of warnings like that one:
CMake Warning (dev) at /usr/local/lib/cmake/opencv4/OpenCVModules.cmake:393 (add_library):
ADD_LIBRARY called with SHARED option but the target platform does not
support dynamic linking. Building a STATIC library instead. This may lead
to problems.
Call Stack (most recent call first):
/usr/local/lib/cmake/opencv4/OpenCVConfig.cmake:126 (include)
CMakeLists.txt:7 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
Then
emmake make
fails on undefined symbols:
error: undefined symbol: _ZN2cv3Mat10deallocateEv
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
My question is : what do I wrong ? How to tell emscripten where are the famous missing symbols (these are the file .so if I understood correctly) ?
This is partially a hack solution.
In the file /usr/local/lib/cmake/opencv4/OpenCVModules.cmake, change every instances of "SHARED" by "STATIC".
In your cmake file, add the line
file( GLOB opencv_js "/path/to/opencvjs/opencv/build_js/lib/*.a")
This part supposes that you compiled opencv by hand.
then refer to my answer to my next question. (in short: use a canvas, do not use cv::imdecode.)

CMake does not find OpenCV

I seem to have an issue with my CMakeLists and opencv.
I am currently using opencv version 2.4 which is confirmed by
pkg-config --modversion opencv
2.4.8
and
dpkg -l libopencv*
which outputs http://pastebin.com/ZJEfLjDX
But for some reason when i cmake a simple program such as
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
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);
return 0;
}
Will cmake not continue due to this error.
CMake Error at /opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVModules.cmake:183 (message):
The imported target "opencv_core" references the file
"/opt/ros/indigo/lib/libopencv_core3.so.3.1.0"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVModules.cmake"
but not all the files it references.
Call Stack (most recent call first):
/opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake:86 (include)
CMakeLists.txt:3 (find_package)
-- Configuring incomplete, errors occurred!
with this 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 project has no ros dependency, and I have no idea why it is looking for OpenCVConfig.cmake inside ros.
A simple locate shows that the correct version is available other places
locate OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/build/OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/build/unix-install/OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/cmake/OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/cmake/templates/OpenCVConfig.cmake.in
/opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake
/usr/local/share/OpenCV/OpenCVConfig.cmake
/usr/share/OpenCV/OpenCVConfig.cmake
but why does it choose to use the one from ros, which I am not sure is even an option if I don't have opencv3.1.0-dev installed?
I know that a solution to this problem would be SET the path. But why can't find_package make use of the 2.4.8 version? I even tried to change the filename of /opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake to /opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake.old, which caused the same error?... Why is cmake not able to find opencv by simple using find_package( OpenCV REQUIRED ), and how do I make it so that it possible to find using this.

In ROS how to publish my own topic?

I am a beginner in ROS.My operation system is Ubuntu 12.04 and my ROS is hydro.After I read some chapters about the "talker and listener" of The Beginner Tutorials in ROS.wiki,I try to write a publisher to publish message to topic "turtle1/com_vel" so that I can control the turtle to run round.But when I try to make my code,it fails.The terminal remind me that
CMake Error at /opt/ros/hydro/share/catkin/cmake/catkinConfig.cmake:72 (find_package):
Could not find a configuration file for package ros.
Set ros_DIR to the directory containing a CMake configuration file for ros.
The file will have one of the following names:
rosConfig.cmake
ros-config.cmake
I guess that there is something wrong with my CMakeLists.txt.But after comparing it with the demo in ROS.wiki,I still can't find the error.
This is my code in cpp file.In this file,I define a publisher named move_turtle.
#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
int main( int argc, char** argv )
{
// initialization
ros::init(argc, argv, "move_turtle");
ros::NodeHandle n;
ros::Publisher move_pub = n.advertise<geometry_msgs::Twist>("turtle1/com_vel",100);
ros::Rate loop_rate(10);
//define the moving rule that I want.It is a circle.
geometry_msgs::Twist com_cicle;
com_cicle.linear.x=3.0;
com_cicle.linear.y=com_cicle.linear.z=0.0;
com_cicle.angular.x=com_cicle.angular.y=0.0;
com_cicle.angular.z=2.0;
while(ros::ok())
{
//publish the msg to topic /tuttle1/com_vel
move_pub.pulish(com_cicle);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
And my CMakeLists.txt is as follows:
cmake_minimum_required(VERSION 2.8.3)
project(move_turtle)
find_package(catkin REQUIRED COMPONENTS
ros
geometry_msgs
turtlesim
)
catkin_package()
include_directories(
${catkin_INCLUDE_DIRS}
)
## Declare a cpp executable
add_executable(move_turtle src/move_turtle.cpp)
## Specify libraries to link a library or executable target against
target_link_libraries(move_turtle ${catkin_LIBRARIES})
Oh...I used 'ros' instead of 'roscpp' in line 5 in 'CMakeLists.txt'.That was why it reminded me that there was no 'ros' package in my path.

How to include OpenCV libraries in CMake Makefile

I hope you can help me.
I have a simple CMakeLists.txt in order to build my project on Leopard 10.5.8.
I'm using CMake 2.8.1 and at the moment this is the code:
cmake_minimum_required(VERSION 2.8)
MESSAGE(STATUS "./src: Going into utils folder")
ADD_SUBDIRECTORY(utils)
MESSAGE(STATUS "./src: utils folder processed")
include_directories(${DIR}/headers)
link_directories (${DIR}/src/utils)
ADD_EXECUTABLE(sample sample.cpp)
TARGET_LINK_LIBRARIES(sample libSample ${EXTERNAL_LIBS})
INSTALL(TARGETS sample DESTINATION "./src")
MESSAGE(STATUS "./src: exiting src folder")
I need to add OpenCV libraries on my project.
When I use Eclipse I set the include path to /opt/local/include
and the libraries path to: /opt/local/lib and then I specify the libraries name such as_ opencv_core, opencv_imgproc, opencv_video.
Can you tell me how to add these information in the CMakeLists.txt file, please?
I've read some information in the official cmake FAQ but i wasn't able to solve my problem.
Please, help me.
Thanks a lot.
You need to add the library names in the TARGET_LINK_LIBRARIES command, but you need to add them without the lib prefix. For example:
include_directories(${DIR}/headers /opt/local/include)
link_directories (${DIR}/src/utils /opt/local/lib)
ADD_EXECUTABLE(sample sample.cpp)
TARGET_LINK_LIBRARIES(sample opencv_core opencv_imgproc opencv_video ${EXTERNAL_LIBS})

Resources