ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

OpenCV Error: Null pointer (NULL or empty buffer) in cvOpenFileStorage

asked 2013-12-16 22:52:10 -0500

chao gravatar image

updated 2015-09-24 01:48:54 -0500

130s gravatar image

Hi, i am trying to use a face detector node in python with follower node in c++. I have copy the whole turtlebot_follower packages and placed the python node inside src. Following is the error message it shows when i tried to run the node:

OpenCV Error: Null pointer (NULL or empty buffer) in cvOpenFileStorage, file /tmp/buildd/ros-groovy-opencv2-2.4.6-1precise-20131020-2316/modules/core/src/persistence.cpp, line 2703
Traceback (most recent call last):
  File "/home/chao/abc/src/turtlebot_follower/nodes/face_detector.py", line 140, in <module>
    FaceDetector(node_name)
  File "/home/chao/abc/src/turtlebot_follower/nodes/face_detector.py", line 42, in __init__
    self.cascade_1 = cv2.CascadeClassifier(cascade_1)
cv2.error: /tmp/buildd/ros-groovy-opencv2-2.4.6-1precise-20131020-2316/modules/core/src/persistence.cpp:2703: error: (-27) NULL or empty buffer in function cvOpenFileStorage

Shutting down vision node.

and this is the python node i placed inside src folder:

#!/usr/bin/env python

""" face_detector.py - Version 1.0 2012-02-11

    Based on the OpenCV facedetect.py demo code

    Extends the ros2opencv2.py script which takes care of user input and image display

    Created for the Pi Robot Project: <a href="http://www.pirobot.org">http://www.pirobot.org</a>
    Copyright (c) 2011 Patrick Goebel.  All rights reserved.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details at:

    <a href="http://www.gnu.org/licenses/gpl.html">http://www.gnu.org/licenses/gpl.html</a>
"""

import roslib; roslib.load_manifest('turtlebot_follower')
import rospy
import cv2
import cv2.cv as cv
from ros2opencv2 import ROS2OpenCV2

class FaceDetector(ROS2OpenCV2):
    def __init__(self, node_name):
        super(FaceDetector, self).__init__(node_name)

        # Get the paths to the cascade XML files for the Haar detectors.
        # These are set in the launch file.
        cascade_1 = rospy.get_param("~cascade_1", "")
        cascade_2 = rospy.get_param("~cascade_2", "")
        cascade_3 = rospy.get_param("~cascade_3", "")

        # Initialize the Haar detectors using the cascade files
        self.cascade_1 = cv2.CascadeClassifier(cascade_1)
        self.cascade_2 = cv2.CascadeClassifier(cascade_2)
        self.cascade_3 = cv2.CascadeClassifier(cascade_3)

        # Set cascade parameters that tend to work well for faces.
        # Can be overridden in launch file
        self.haar_scaleFactor = rospy.get_param("~haar_scaleFactor", 1.3)
        self.haar_minNeighbors = rospy.get_param("~haar_minNeighbors", 3)
        self.haar_minSize = rospy.get_param("~haar_minSize", 30)
        self.haar_maxSize = rospy.get_param("~haar_maxSize", 150)

        # Store all parameters together for passing to the detector
        self.haar_params = dict(scaleFactor = self.haar_scaleFactor,
                                minNeighbors = self.haar_minNeighbors,
                                flags = cv.CV_HAAR_DO_CANNY_PRUNING,
                                minSize = (self.haar_minSize, self.haar_minSize),
                                maxSize = (self.haar_maxSize, self.haar_maxSize)
                                )

        # Do we should text on the display?
        self.show_text = rospy.get_param("~show_text", True)

        # Intialize the detection box
        self.detect_box = None

        # Track the number of hits and misses
        self.hits = 0
        self.misses = 0
        self.hit_rate = 0

    def process_image(self, cv_image):
        # Create a greyscale version of the ...
(more)
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2013-12-17 01:35:31 -0500

chao gravatar image

hi, i managed to solve this already. The problem caused by the missing XML files. I just have to specify the path under param will do.

# Get the paths to the cascade XML files for the Haar detectors.
# These are set in the launch file.
cascade_1 = rospy.get_param("~cascade_1", "")
cascade_2 = rospy.get_param("~cascade_2", "")
cascade_3 = rospy.get_param("~cascade_3", "")
edit flag offensive delete link more
1

answered 2015-09-24 18:27:30 -0500

130s gravatar image

Maybe just a clarification of @chao's answer.

I had the same error message that was because the classifier parameters weren't available. I ensured that classifier.yaml was passed to the Parameter server in the launch file (as one of the launch files does like this):

<rosparam command="load" file="$(find face_detector)/param/classifier.yaml"/>

Note that if you're using binary (i.e. you installed the package probably by apt-get) on Indigo, use version 1.0.9 or higher (ref).

edit flag offensive delete link more
0

answered 2014-04-21 01:45:27 -0500

Hejab gravatar image

What should we do if we get a same type of error in C++ open cv working in visual studio??

edit flag offensive delete link more

Comments

Please refrain from posting a new question as an answer (otherwise you won't get any answer to your question).

130s gravatar image 130s  ( 2015-09-24 01:47:12 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-12-16 22:52:10 -0500

Seen: 14,558 times

Last updated: Sep 24 '15