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

asked 2018-06-19 05:54:06 -0600

facedemo gravatar image

updated 2018-06-19 07:47:20 -0600

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 https://www.pyimagesearch.com/2018/02...

When I run the python script with the command

python detect_faces.py --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 "detect_faces.py", 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/setup.bash.in

CATKIN_SHELL=bash

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

I don't understand these files, it's quite new to me, but as it seems, the problem is that the script detect_faces.py 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 https://github.com/yoshito-n-students... 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 detect_faces.py from the tutorial

# USAGE
# python detect_faces.py --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 ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by facedemo
close date 2018-06-20 07:28:04.786549

Comments

1

i somewhat doubt, that you need ROS to communicate with a webcam.

most likely, you're better off, installing a more recent cv2, and just use the official sample

berak gravatar imageberak ( 2018-06-19 06:25:25 -0600 )edit
1

the camera is an external industrial camera, not a webcam. The ROS configuration was already set from before. I could of course try to load the images from the camera to a folder in the computer, without using ROS, but since I don't have much knowledge of how to do I would prefer not to go there... I believe there should be a way

facedemo gravatar imagefacedemo ( 2018-06-19 07:36:54 -0600 )edit

I have actually made another face detection, like the one you mention berak, with ROS using a different tutorial. I would like to do different versions and try which one works best

facedemo gravatar imagefacedemo ( 2018-06-19 07:40:42 -0600 )edit

unfortunately, we can't help at all with ROS problems from here.

berak gravatar imageberak ( 2018-06-19 07:42:13 -0600 )edit
1

@facedemo, an assertion triggered because of wrong dimensions / type of input blob. Can you check a type and a shape of blob which is used at setInput? Please also check a .caffemodel size and if it's not impossible to use the latest state of OpenCV instead mentioned 3.3.1, try to find a .caffemodel and .prototxt from the corresponding version of source code.

dkurt gravatar imagedkurt ( 2018-06-19 07:42:59 -0600 )edit

@dkurt, shape of blob is (1, 3, 300, 300), how do I check type?

facedemo gravatar imagefacedemo ( 2018-06-19 07:53:53 -0600 )edit

@berak thanks for your answers

facedemo gravatar imagefacedemo ( 2018-06-19 07:54:47 -0600 )edit

@dkurt size of .caffemodel is 300x300, is it okay? Thanks for your answers!

facedemo gravatar imagefacedemo ( 2018-06-19 07:59:21 -0600 )edit
1

https://github.com/yoshito-n-students... -- please don't try that, it's even older, than the outdated one you have now.

and the type is:

blob.dtype

(should be dtype('float32'))

berak gravatar imageberak ( 2018-06-19 08:11:09 -0600 )edit

hahah okay, I won't try that... thanks for your advice @berak

the type is correct, float32

I did not understand this: "and if it's not impossible to use the latest state of OpenCV instead mentioned 3.3.1, try to find a .caffemodel and .prototxt from the corresponding version of source code." What do you mean here?

facedemo gravatar imagefacedemo ( 2018-06-19 08:39:32 -0600 )edit