Not returning the msg i wanted in a Class.

asked 2019-07-12 06:02:14 -0600

loguna gravatar image

updated 2019-07-12 06:05:53 -0600

I have a problem, the code below does not return the image data back to my depth function. It returns a 'None' type object back instead. May I know what can i do to achieve the result i want? Below is my code:

!/usr/bin/env python

from __future__ import print_function

import roslib import sys import rospy import cv2 from std_msgs.msg import Int32 from sensor_msgs.msg import Image from cv_bridge import CvBridge, CvBridgeError import numpy as np from geometry_msgs.msg import Twist import argparse import time import os import threading

cv_image = cv2.imread ('image_photo_taken.jpg') def mouse_drawing (event,x,y,flags,params): if event == cv2.EVENT_LBUTTONDOWN:

x = x
y = y
print(x , y)

def test():


class image_converter:

def __init__(self):

self.cv_image2 = None

def __call__(self,data):

#self.bridge = CvBridge()
 # self.cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
#except CvBridgeError as e:
 # print(e)
 #cv_image = cv2.imread("toilet_door_16.jpg")
#self.cv_image = cv2.resize(self.cv_image,(300,300),fx=0,fy=0, interpolation = cv2.INTER_CUBIC)


self.cv_image2 = data

def callback (self):

return self.cv_image2

def depth_callback(data): bridge = CvBridge() try: # We select bgr8 because its the OpneCV encoding by default cv_image_depth = bridge.imgmsg_to_cv2(data,desired_encoding='32FC1') except CvBridgeError as e: print(e) #pub = rospy.Publisher('depthoutput',Int32,queue_size=10) movement = 'keepgoing' cv_image_depth = cv2.resize(cv_image_depth, (200,200),fx=0,fy=0, interpolation = cv2.INTER_CUBIC) cv2.imshow("depth",cv_image_depth) cv2.waitKey(1) test = cv2.setMouseCallback("depth",mouse_drawing) #print (cv_image_depth [150,150]) x = 0 count_black = 0 count_white = 0 while x < 200: y =0 while y < 200: depth= cv_image_depth [x,y] if depth == 0: count_black = count_black +1 elif depth < 700: count_black = count_black +1 else: count_white = count_white + 1 y = y +1 x = x+1 if count_white > count_black: movement = 1 print("keep going")

else: call1 = image_converter() rospy.Subscriber("/camera/rgb/image_raw",Image,call1) msg = call1.callback() print(msg)

#msg needed for futher processing

def main(args): ic = test() rospy.init_node('depth_image', anonymous=True)

try: rospy.spin() except KeyboardInterrupt: print("Shutting down") cv2.destroyAllWindows()

if __name__ == '__main__': main(sys.argv)

edit retag flag offensive close merge delete