Opencv linking libraries - opencv

i have installed opencv 3.1.0 and i want to compile following program:
#include <stdio.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
int main(void){
return 0;
}
but it returns error:undefined reference to cvRound and so on in header file types_c.h.
I know it must be a linking problem but the only libraries i can link are:
opencv_world310.lib, opencv_world310d.lib
I have already tried to link these but that doesn't solve the problem.
I m using a GNU GCC Compiler and dynamic libraries a link with mingw32-g++.exe.
According to some research in the internet i need to link libraries like:
`opencv_calib3d249d.lib`
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib`
but those are not in my lib directory!

Related

Opencv DNN module was not built with CUDA backend, however it was built [duplicate]

I am trying to run YOLOv3 on Visual Studio 2019 using CUDA 10.2 with cuDNN v7.6.5 on Windows 10 using NVidia GeForce 930M. Here is part of the code I used.
#include <fstream>
#include <sstream>
#include <iostream>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace dnn;
using namespace std;
int main()
{
// Load names of classes
string classesFile = "coco.names";
ifstream ifs(classesFile.c_str());
string line;
while (getline(ifs, line)) classes.push_back(line);
// Give the configuration and weight files for the model
String modelConfiguration = "yolovs.cfg";
String modelWeights = "yolov3.weights";
// Load the network
Net net = readNetFromDarknet(modelConfiguration, modelWeights);
net.setPreferableBackend(DNN_BACKEND_CUDA);
net.setPreferableTarget(DNN_TARGET_CUDA);
// Open the video file
inputFile = "vid.mp4";
cap.open(inputFile);
// Get frame from the video
cap >> frame;
// Create a 4D blob from a frame
blobFromImage(frame, blob, 1 / 255.0, Size(inpWidth, inpHeight), Scalar(0, 0, 0), true, false);
// Sets the input to the network
net.setInput(blob);
// Runs the forward pass to get output of the output layers
vector<Mat> outs;
net.forward(outs, getOutputsNames(net));
}
Although I add $(CUDNN)\include;$(cudnn)\include; to Additional Include Directories in both C/C++ and Linker, added CUDNN_HALF;CUDNN; to C/C++>Preprocessor Definitions, and added cudnn.lib; to Linker>Input, I still get this warning:
DNN module was not built with CUDA backend; switching to CPU
and it runs on CPU instead of GPU, can anyone help me with this problem?
I solved it by using CMake, but I had first to add this opencv_contrib then rebuilding it using Visual Studio. Make sure that these WITH_CUDA, WITH_CUBLAS, WITH_CUDNN, OPENCV_DNN_CUDA, BUILD_opencv_world are checked in CMake.
I had a similar issue happen to me about a week ago, but I was using Python and Tensorflow. Although the languages were different compared to C++, I did get the same error. To fix this, I uninstalled CUDA 10.2 and downgraded to CUDA 10.1. From what I have found, there might be a dependency issue with CUDA, or in your case, OpenCV hasn't created support yet for the latest version of CUDA.
EDIT
After some further research it seems to be an issue with Opencv rather than CUDA. Referencing this github thread, if you installed Opencv with cmake, remove the arch bin version below 7 on the config file, then rebuild/reinstall Opencv. However, if that doesn't work, another option would be to remove CUDA arch bin version < 5.3 and rebuild.

Using OMPL with Drake

I am trying to work with ompl on drake and am having issues with using the ompl headers in drake. I installed ompl using the default installation path and made the following changes in drake:
Added the following to the workspace:
new_local_repository(
name = "ompl",
path = "/usr/local/include/ompl-1.5/ompl",
build_file = "ompl.BUILD",
)
ompl.BUILD:
cc_library(
name = "ompl",
hdrs = glob(["**"]),
includes = ["include"],
visibility = ["//visibility:public"],
linkstatic = 1,
)
In my repository's BUILD.bazel:
drake_cc_binary(
name = "ompl_ex",
srcs = ["src/ompl_ex.cc"],
data = [],
test_rule_args = ["--target_realtime_rate=0.0"],
deps = [
"#gflags",
"#ompl//:ompl",
],
)
ompl_ex.cc
#include <memory>
#include <limits.h>
#include <unistd.h>
#include <fstream>
#include <string>
#include <gflags/gflags.h>
#include <iostream>
#include <ompl/config.h>
#include <vector>
namespace drake {
namespace ompl {
int DoMain(){
std::cout<<"the function is working"<<std::endl;
return 0;
}
} // namespace examples
} // namespace drake
int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
return drake::ompl::DoMain();
}
The error I get:
infinite_horizon_ltl/src/ompl_ex.cc:10:10: fatal error: ompl/config.h: No such file or directory
#include <ompl/config.h>
I use spot libraries similarly and they seem to be working fine. Not sure what I am getting wrong in the case of OMPL. I checked on drakes git issues and found that there was an attempt at integration but the branch is deleted now, and the solution proposed does not seem to be working on my system.
I have found that it is easiest to work with drake as an external library in a cmake project. This works quite well with ompl. Here's a quick example which imports both drake and ompl as external libraries and solves a simple planning problem.
https://github.com/DexaiRobotics/drake-torch/tree/master/examples/drake-ompl
The output and video were made using the dexai2/drake-torch/cpu-nightly-ros docker which is available here: https://hub.docker.com/r/dexai2/drake-torch/tags
As an aside, depending on which version of Ubuntu you use, you may need change your gcc version - e.g. you need gcc-9 and g++-9 specified in the CMakeLists.txt for Ubuntu 20.04 and gcc-7 and g++-7 on 18.04. See notes here: https://drake.mit.edu/developers.html#id10

How to make use of OpenCV source codes instead of shared libraries

I have a project at hand which I want to use one of the opencv modules (specifically dnn).
Instead of building the dnn module I want to use the source code of this modules in my project. by doing so, I can change the source code live and see the results at the same time.
I have a very simple scenario with one only source file:
main.cpp
#include "iostream"
#include <opencv2/dnn.hpp>
int main(int argc, char *argv[])
{
std::string ConfigFile = "tsproto.pbtxt";
std::string ModelFile = "tsmodel.pb";
cv::dnn::Net net = cv::dnn::readNetFromTensorflow(ModelFile,ConfigFile);
return 0;
}
now this function "cv::dnn::readNetFromTensorflow" is in dnn module. I tried many different methods to embedded the dnn source codes inside my project but all of them failed !
for example, the first time I tried to include every cpp and hpp file in the module/dnn/ folder of opencv in my project but I ended up in errors like
/home/user/projects/Tensor/tf_importer.cpp:28: error: 'CV__DNN_EXPERIMENTAL_NS_BEGIN' does not name a type
#include "../precomp.hpp" no such file or directory
HAVE_PROTOBUF is undefined
and ....
I tried to solve these errors but some more errors just happened, more undefined MACROs and more undefined hpp files !
#include "../layers_common.simd.hpp" no such file or directory
and many many more errors !
It seems that I'm stuck in a while(true) loop of errors !!! Is it really that hard to use opencv modules source code ?
P.S.
For those who are asking about why I want to use opencv source code instead of using the shared libraries I have to say that I want to import a customized tensorflow model which opencv read function doesn't support and I want to know where exactly it crashesh so I can fix it.
By the way, I am only using c++11 functions and gcc as compiler in Ubuntu 16.04

Error C1189 d3d10.h is included before d3d10_1.h

aI'm trying to make a Component based 3d engine and I'm getting this error over and over again, here it is:
error C1189: #error : d3d10.h is included before d3d10_1.h, and it will confuse tools that honor SAL annotations. If possibly targeting d3d10.1, include d3d10_1.h instead of d3d10.h, or ensure d3d10_1.h is included before d3d10.h c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d10_1.h 75
I suspect (but not sure) this came out when I created this h file:
#pragma once
#include <D3DX10math.h>
typedef D3DXVECTOR2 Vector2;
typedef D3DXVECTOR3 Vector3;
typedef D3DXVECTOR4 Vector4;
typedef D3DXMATRIX Mat4;
And my d3dclass include part:
#include <Windows.h>
#include <D3D11.h>
#include <D3DX11.h>
#include <DXGI.h>
#include <D3Dcommon.h>
I'm using the directx SDK june 2010
Please help
Thanks!

VideoCapture OpenCV 2.4.2 error in windows

I have a problem using VideoCapture class with OpenCV 2.4.2 under windows XP 32bits.
It doesn't open any file or camera and fixing it's being a pain.
Im using visual studio 2010 but i have also tried the code in QTcreator with the same result.
The testing code is the following:
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace cv;
using namespace std;
int main()
{
const char* videoPath = "C:/video/";
string videoName = string(videoPath) + "avi.avi";
VideoCapture cap(videoName);
if(!cap.isOpened())
{
std::cout<<"Fail"<<std::endl;
return -3;
}
return 0;
}
The output is always '-3'.
Qt Creator shows a
warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:361)
I debugged it and the problem appears in the first line of:
CvCapture* cvCreateFileCapture_FFMPEG_proxy(const char * filename)
{
CvCapture_FFMPEG_proxy* result = new CvCapture_FFMPEG_proxy;
if( result->open( filename ))
return result;
delete result;
#if defined WIN32 || defined _WIN32
return cvCreateFileCapture_VFW(filename);
#else
return 0;
#endif
}
in the cap_ffmpeg.cpp internal file.
I have tested the same code in a mac under snow leopard and it works. No surprises here since it must be a library issue.
I have opened the avi file with the same path route using the c-function cvCapture easy and fast.
I got all the dlls of 'C:\opencv\opencv\build\x86\vc10\bin'
included in mi debug file. I got the tbb.dll and all the 'C:\opencv\opencv\3rdparty\ffmpeg' content included too.
This is drving me crazy so any help would be appreciated.
Thanks in advance.
In my case, the same problem was resolved after deleting all opencv_***.dll files in C:\Windows\System32. So, I use the dll files just through the path like "%PATH%;C: \Program Files \OpenCV2.4.2\build\x86\vc10/bin". Please try it.
I also faced with this problem and solved it by correct the path of the function:
VideoCapture cap(videoName);
If the AVI file of videoName does't exist, it will be an error:
(../../modules/highgui/src/cap_ffmpeg_impl.hpp:XXX)
where XXX represents the line number.
I had the same issue with the open method whilst running under Windows 8 (64bit), opencv 2.4.10. IDE is running in x86.
I found that running the application in release configuration solved the problem.
Stumbled across the answer because I had the same issue with imread. Issue is presented in the this thread.
imread not working in Opencv
See the fix I found below, for mp4 files.
I faced the same issue on Windows 7, using OpenCV 2.4.9. I am using the java wrapper for opencv.
Matthias Krings has done a lot of research for this. See this. Apparently this is an issue based on the video file type. With .avi files, it seems to work for a lot of people. Unfortunately his solution of setting OPENCV_DIR did not work for me. But his comments in the bug listing gave me a hint to fix the issue.
You have to do two things:
Set java.library.path to include the directory {opencv\install\dir}opencv-2.4.9\build\x86\vc10\bin. You can set the variable using the -D option on the java command line: java -Djava.library.path=PATH_TO_YOUR_DLL .... Also fetch this variable from your environment, using System.getProperty(...), and print it before calling loadLibrary(), to verify that the path setting is working.
And in your java class, load the ffmpeg dll using System.loadLibrary("opencv_ffmpeg249");. The loadLibrary() function should be invoked from within a static block in java.
There is a file named opencv_ffmpeg249.dll in the java.library.path that we set.
This works on ubuntu also, for .so files.
I too faced the same issue and resolved after pointing to the correct location of the input video.

Resources