Not returning the msg i wanted in a Class.
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 stdmsgs.msg import Int32 from sensormsgs.msg import Image from cvbridge import CvBridge, CvBridgeError import numpy as np from geometrymsgs.msg import Twist import argparse import time import os import threading
cvimage = cv2.imread ('imagephototaken.jpg') def mousedrawing (event,x,y,flags,params): if event == cv2.EVENT_LBUTTONDOWN:
x = x
y = y
print(x , y)
def test():
rospy.Subscriber("/camera/depth/imageraw",Image,depthcallback)
class image_converter:
def init(self):
self.cv_image2 = None
def call(self,data):
#self.bridge = CvBridge()
#try:
# 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)
#cv2.imshow('cv_image',self.cv_image)
self.cv_image2 = data
def callback (self):
return self.cv_image2
def depthcallback(data): bridge = CvBridge() try: # We select bgr8 because its the OpneCV encoding by default cvimagedepth = bridge.imgmsgtocv2(data,desiredencoding='32FC1') except CvBridgeError as e: print(e) #pub = rospy.Publisher('depthoutput',Int32,queuesize=10) movement = 'keepgoing' cvimagedepth = cv2.resize(cvimagedepth, (200,200),fx=0,fy=0, interpolation = cv2.INTERCUBIC) cv2.imshow("depth",cvimagedepth) cv2.waitKey(1) test = cv2.setMouseCallback("depth",mousedrawing) #print (cvimagedepth [150,150]) x = 0 countblack = 0 countwhite = 0 while x < 200: y =0 while y < 200: depth= cvimagedepth [x,y] if depth == 0: countblack = countblack +1 elif depth < 700: countblack = countblack +1 else: countwhite = countwhite + 1 y = y +1 x = x+1 if countwhite > count_black: movement = 1 print("keep going")
else: call1 = imageconverter() rospy.Subscriber("/camera/rgb/imageraw",Image,call1) msg = call1.callback() print(msg)
#msg needed for futher processing
def main(args): ic = test() rospy.initnode('depthimage', anonymous=True)
try: rospy.spin() except KeyboardInterrupt: print("Shutting down") cv2.destroyAllWindows()
if name == 'main': main(sys.argv)
Asked by loguna on 2019-07-12 06:02:14 UTC
Comments