Ask Your Question
0

unable to build application in linux based on opencv::dnn module

asked 2020-02-05 10:26:52 -0600

aquarian-source gravatar image

updated 2020-02-06 07:49:03 -0600

berak gravatar image

hey everyone. i have written an application for implementing YOLO in c++ using opencv::dnn module. it works fine in windows but in linux i am unable to compile and build this application. actually i am unable to include dnn module in build process. can anyone guide me in this regard.

Error i get: "dnn" is not a namespace. (In) using namespace cv::dnn. Where ever i have used dnn it has given error there.

i am using opencv 4.1.0 ubuntu 16.04 and cmake build process

to show exactly what i am doing: i install opencv4.1.0 following this tutorial. https://www.youtube.com/watch?v=2Pboq... also i have "sdk" for cross compiling that also has opencv 4.1.0. when i do pkg-config --cflags opencv it gives path /usr/include/opencv and when i look for librares(pkg-config --libs opencv) it gives path for libs in "sdk".

now i take my code(that is working in windows) in ubuntu envrionment and try to build it with cmake. cmake script is below :

CMake script: cmake_minimum_required(VERSION 3.5)
project(OD_display)
add_compile_options(-std=c++11)
find_package(OpenCV)

include_directories(
      include
      ${OpenCV_INCLUDE_DIRS}
)

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(${PROJECT_NAME} src/source.cpp)
target_link_libraries(${PROJECT_NAME}
     ${OpenCV_LIBRARIES}
)

and message status comes out to be:

OpenCV library status:
--     config: /usr/share/OpenCV
--     version: 2.4.9.1
--     libraries: opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_ocl;opencv_objdetect;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d
--     include path: /usr/include/opencv;/usr/include
-- Configuring done
-- Generating done

Make file gives multiple errors like this

/home/rizwan/Desktop/OD_ubuntu/include/Object_Detection.h:10:21: error: ‘dnn’ is not a namespace-name
 using namespace cv::dnn;

                 ^
/home/rizwan/Desktop/OD_ubuntu/include/Object_Detection.h:10:24: error: expected namespace-name before ‘;’ token
 using namespace cv::dnn;
                        ^
/home/rizwan/Desktop/OD_ubuntu/include/Object_Detection.h:26:37: error: ‘dnn’ in namespace ‘cv’ does not name a type
  vector<String> getOutput(const cv::dnn::Net& net);
edit retag flag offensive close merge delete

Comments

please add error messages

berak gravatar imageberak ( 2020-02-05 10:54:21 -0600 )edit

you probably need to show us, what you include, where and how ...

berak gravatar imageberak ( 2020-02-06 04:10:01 -0600 )edit
1

my bad, i add more details

aquarian-source gravatar imageaquarian-source ( 2020-02-06 07:16:25 -0600 )edit
1

@barek thankyou for editing the post. it looks more understandable now

aquarian-source gravatar imageaquarian-source ( 2020-02-06 08:06:38 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2020-02-06 07:52:02 -0600

berak gravatar image

updated 2020-02-06 07:56:25 -0600

-- version: 2.4.9.1

this is outdated, no more maintained and does not contain any dnn module.

please uninstall it, and try to use a recent release instead

(try not to use your bad package manager here ..)

later, don't forget to

#include <opencv2/dnn.hpp>

in your code.

edit flag offensive delete link more

Comments

although i install 4.1.0 but it shows 2.4 here. anyways i install 4.1 again. just one question. if my code works in windows what changes would i have to do in ubuntu? and also i did not include #include <opencv2 dnn.hpp=""> in windows. if its necessary to add here then why? just for concept

aquarian-source gravatar imageaquarian-source ( 2020-02-06 08:04:55 -0600 )edit
1

if my code works in windows what changes would i have to do in ubuntu?

nothing.

berak gravatar imageberak ( 2020-02-06 08:32:34 -0600 )edit

You most likely are linking to the wrong open cv version - 2.4.9.1 instead of 4.1.0. Or in the case of a static build (please dont hit me i am no c++ professional if this is not correct terminology) you are including the wrong header files.

holger gravatar imageholger ( 2020-02-06 11:22:43 -0600 )edit

i have correctly installed opencv4.1.0 and i use this version. now i have built properly. now when i run the exe file it gives this error


terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.1.0) /home/rizwan/Desktop/opencv/modules/imgproc/src/resize.cpp:3718: error: (-215:Assertion failed) !ssize.empty() in function 'resize'


now i have two questions:

  1. what is the correct way for executing yolo( using opencv::dnn) built model in Ubuntu. like at the moment i run executable with four arguments. config file, weigths, list.names, and a picture.
  2. this code was executed in windows opencv4.1.0 with errors. why is it giving me this error?
aquarian-source gravatar imageaquarian-source ( 2020-02-13 03:25:22 -0600 )edit
1

error: (-215:Assertion failed) !ssize.empty()

your image was not loaded correctly, check path to it, again

berak gravatar imageberak ( 2020-02-13 03:45:08 -0600 )edit

it is in the same folder as the exe file. and i am giving it as an argument like this

./OD_app yo.PNG yolov3-tiny.cfg yolov3-tiny.weights

i dont think so that path is the problem.

aquarian-source gravatar imageaquarian-source ( 2020-02-13 03:50:19 -0600 )edit
1

Did you checked this - even when it sounds stupid to you. Check the loaded mat - how many rows / cols they have(log it on console or debug it). Opencv will NOT throw an exception when image could not be loaded - you just have an empty mat and following operation on it can fail. This is the root cause of like 70% of all problems here. You can argue for and against this behaviour - just be aware of it.

And it wont hurt to use an absolute path for now to go very sure - i dont want to spend hours just to realize my path was maybe resolve relatived to my working dir - which was not the one i expected (ide's do sometimes funny stuff). So i always do this when i start something new, regardless of the library.

holger gravatar imageholger ( 2020-02-13 13:11:18 -0600 )edit

Its obvious - berak is right error: (-215:Assertion failed) !ssize.empty(). I mean its even in the error message that the image is empty and an assert checking this fails.

holger gravatar imageholger ( 2020-02-13 14:39:28 -0600 )edit

i have tried to give absolute path as well it gives same error. question is: there are 4 inputs to the model.

  1. configuration file for dnn
  2. weigths
  3. names of object(data list)
  4. input image to run yolo

what is right way to give them as inputs? just like arguments as i have been giving?

./OD_app yo.PNG yolov3-tiny.cfg yolov3-tiny.weights

aquarian-source gravatar imageaquarian-source ( 2020-02-17 05:17:05 -0600 )edit

how would we know, how your OD_app takes cmdline args w/o code ?

berak gravatar imageberak ( 2020-02-17 06:02:11 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-02-05 10:26:52 -0600

Seen: 2,673 times

Last updated: Feb 06 '20