ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

ros kinetic dnn -- OpenCV Error: Assertion failed -- cv2.error -- error: (-215) -- .bashrc -- deep learning [closed]

asked 2018-06-19 04:04:23 -0500

facedemo gravatar image

updated 2018-06-19 08:02:47 -0500

Hi, I'm doing a project including ROS and OpenCV. ROS kinetic is used for the communication between a camera (an external industry camera) and the computer (Ubuntu 16.04 LTS). I follow the guide/tutorial for Face detection with OpenCv and deep learning on

When I run the python script with the command

python --image rooster.jpg --prototxt deploy.prototxt.txt --model res10_300x300_ssd_iter_140000.caffemodel

I get this error

[INFO] loading model...
[INFO] computing object detections...
[ INFO:0] Initialize OpenCL runtime...
OpenCV Error: Assertion failed (input.dims == 4 && (input.type() == 5 || input.type() == 6)) in finalize, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/dnn/src/layers/convolution_layer.cpp, line 78
Traceback (most recent call last):
  File "", line 41, in <module>
    detections = net.forward()
cv2.error: /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/dnn/src/layers/convolution_layer.cpp:78: error: (-215) input.dims == 4 && (input.type() == 5 || input.type() == 6) in function finalize

The problem ONLY appears when I have this line included in my .bashrc-file in the home directory

# -------- ROS DEPENDENCIES -------------
source /opt/ros/kinetic/setup.bash

The setup.bash-file contains

#!/usr/bin/env bash
# generated from catkin/cmake/templates/


# source from same directory as this file
_CATKIN_SETUP_DIR=$(builtin cd "`dirname "${BASH_SOURCE[0]}"`" > /dev/null && pwd)

I don't understand these files, it's quite new to me, but as it seems, the problem is that the script can't work when OpenCV is installed with ROS... does anyone understand the problem?

What is missing from OpenCV with ROS for this to work? Should I download a new package or add something in the bashrc-file? Or use an cv bridge?

Just to clearify, I haven't incorporated ROS with this script yet. I wanted to make it to work without reading from the camera, and only read a saved image in a folder to begin with.

. . . . .

I've found this package here which says "A ROS package containing OpenCV's dnn module that is missing in OpenCV bundled with ROS".

How do I do to try this package?

For better understanding, this is the code for from the tutorial

# python --image rooster.jpg --prototxt deploy.prototxt.txt --model res10_300x300_ssd_iter_140000.caffemodel

# import the necessary packages
import numpy as np
import argparse
import cv2

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
    help="path to input image")
ap.add_argument("-p", "--prototxt", required=True,
    help="path to Caffe 'deploy' prototxt file")
ap.add_argument("-m", "--model", required=True,
    help="path to Caffe pre-trained model")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
    help="minimum probability to filter weak detections")
args = vars(ap.parse_args())

# load our serialized model from disk
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"])

# load the input image and construct an input blob for the image
# by ...
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by facedemo
close date 2018-06-20 07:26:46.746892

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-20 07:24:47 -0500

facedemo gravatar image

As I understand it, it has something to do with this problem too

As the answer says, the OpenCV package that is installed with ROS already include the extra-modules with exception of the neural networks. Since I don't find a solution to this either, this problem is now closed

edit flag offensive delete link more


I am having the same problem. However when I checked /opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/ the dnn folder is there so I am not sure whether the problem is that ROS opencv does not include dnn. Anyway I think we should open the question again to find the real solution to the problem In a separated note, did you manage to solve it?

mihota gravatar image mihota  ( 2019-04-01 01:32:07 -0500 )edit

Question Tools



Asked: 2018-06-19 04:04:23 -0500

Seen: 1,240 times

Last updated: Jun 20 '18