Ask Your Question

Opencv Error

asked 2020-02-09 15:32:25 -0500

GGR007 gravatar image

Hello i use opencv in ros melodic on ubuntu 18, i use a kinectv2 for FullHd image, and an combination of filter to recognize ad object, in the same node have a topic witch pub the obj position. This is a code used for read the value of this point in depth image, is a 'mono16' image, but i have this error.

#!/usr/bin/env python

import roslib
import sys
import rospy
import cv2
import math, time
import numpy as np

from std_msgs.msg import String
from sensor_msgs.msg import Image
from geometry_msgs.msg import Point
from cv_bridge import CvBridge, CvBridgeError

class image_converter_depth :
    def __init__(self):

        self._t0 = time.time()
        self.obj_point = Point()

        self.blob_x         = 0.0
        self.blob_y         = 0.0
        self._time_detected = 0.0

        self.blob_sub = rospy.Subsciber("blob/point_blob",Point, self.update_blob)
        rospy.loginfo("Subsciber to blob point set")
        self.image_pub = rospy.Publisher("Depth_image",Image)
        rospy.loginfo("Publisher with circle in  depth image ")
        self.obj_pub = rospy.Publisher("blob/obj_point",Point)
        self.bridege = CVBridge()
        self.image_sub = rospy.Subsciber("/kinect2/sd/image_depth",Image,self.callback)
        rospy.loginfo("Subsciber sd to depth image ")

    def callback(self,data):
        except CvBridgeError as e :
            if ((int(rows/2))<int(self.blob_x)<(1920-int(rows/2))):
                if (int(cols/2)<int(self.blob_y)<1080-int(cols/2)):
                    """x_depth = self.blob_x-(960-int(rows/2))
                    y_depth = self.blob_y-(540-int(cols/2))
                    self.obj_point.z = cv_image[x_depth,y_depth]
          , (50,50), 10, 255)
    except CvBridgeError as e :

def is_detected(self):
        return(time.time() - self._time_detected < 1.0)
def update_blob(self,message):
    self.blob_x = message.x
    self.blob_y = message.y
    self._time_detected = time.time()

def main (args):
    ic = image_converter_depth()
    rospy.init("Get_Obj_Pos", anononymus=True)
    except KeyboardInterrupt:
        print("Shutting down")

if __name__ == '__main__':

and the error is

Traceback (most recent call last):
  File "/home/finokkio/catkin_ws/src/Get_Obj_Pos/src/", line 67, in <module>
  File "/home/finokkio/catkin_ws/src/Get_Obj_Pos/src/", line 58, in main
    ic = image_converter_depth()
  File "/home/finokkio/catkin_ws/src/Get_Obj_Pos/src/", line 26, in __init__
    self.blob_sub = rospy.Subsciber("blob/point_blob",Point, self.update_blob)
AttributeError: 'module' object has no attribute 'Subsciber'
edit retag flag offensive close merge delete


self.blob_sub = rospy.Subsciber("blob/point_blob",Point, self.update_blob)

It's Subscriber, not Subsciber.

Note the r after the c.

gvdhoorn gravatar image gvdhoorn  ( 2020-02-09 15:39:07 -0500 )edit

thanks but now i have this error

GGR007 gravatar image GGR007  ( 2020-02-09 15:41:09 -0500 )edit
Traceback (most recent call last):
  File "/home/finokkio/catkin_ws/src/Get_Obj_Pos/src/", line 16, in <module>
    class image_converter_depth :
  File "/home/finokkio/catkin_ws/src/Get_Obj_Pos/src/", line 50, in image_converter_depth
NameError: name 'self' is not defined
GGR007 gravatar image GGR007  ( 2020-02-09 15:41:20 -0500 )edit

You also misspelled self.bridege = CVBridge()

Please do look over your code a little bit.

stevemacenski gravatar image stevemacenski  ( 2020-02-09 17:31:42 -0500 )edit

thanks i correct but have the same error

GGR007 gravatar image GGR007  ( 2020-02-10 03:42:11 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-10 18:52:43 -0500

jayess gravatar image

Try indenting the line

except CvBridgeError as e :

so that's a part of the callback method. That's why the error says

NameError: name 'self' is not defined

because it's not part of the method. Remember that indentation is very important for Python.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-02-09 15:32:25 -0500

Seen: 210 times

Last updated: Feb 10 '20