refine_grasp_point_middle.py
Go to the documentation of this file.
00001 print 'REFINE_GRASP_POINT_MIDDLE.PY IS DEPRECATED, USE REFINE_GRASP_POINT.PY INSTEAD. Waiting for 10 annoying sec more.'
00002 import time
00003 time.sleep(10)
00004 
00005 import os
00006 import numpy as np
00007 
00008 from iri_bow_object_detector.pcl2numpy import get_auto
00009 from geometry_msgs.msg import Point
00010 from iri_perception_msgs.msg import ImagePoint
00011 from iri_bow_object_detector.srv import RefineGraspPoint
00012 
00013 import cv2
00014 from cv_bridge import CvBridge, CvBridgeError
00015 
00016 #import ipdb
00017 
00018 
00019 def select_grasp_point_middle(req):
00020         P=[(box.point1.x, box.point1.y, box.point2.x, box.point2.y, box.value ) for box in req.posible_solutions]
00021         P.sort(key=lambda x:x[4], reverse=True)
00022         if len(P) < 1:
00023                 return Point(0,0,0)
00024 
00025         maxp2du = P[0][0] + (P[0][2] - P[0][0])/2
00026         maxp2dv = P[0][1] + (P[0][3] - P[0][1])/2
00027         maxp2d = (maxp2du, maxp2dv)
00028 
00029         #(XX, YY, ZZ, W) = get_auto(req.pointcloud, [("pos", 0), ("curv", 4)])
00030         #res = Point(XX[maxp2dv, maxp2du], YY[maxp2dv, maxp2du], ZZ[maxp2dv, maxp2du])
00031 
00032         # Draw boxes
00033         ## show result
00034         bridge = CvBridge()
00035         try:
00036                 image = bridge.imgmsg_to_cv(req.image, "bgr8")
00037         except CvBridgeError, e:
00038                 print e
00039 
00040         probs = [wi[4] for wi in P]
00041         maxprob = max(probs)
00042         minprob = min(probs)
00043         for ii,wi in enumerate(P):
00044                 if minprob==maxprob:
00045                         wi_color = 255
00046                 else:
00047                         wi_color = int(np.round(255*((wi[4]-minprob)/(maxprob-minprob))))
00048                 cv2.rectangle(image,(wi[0],wi[1]), (wi[2],wi[3]), (0, 0, wi_color), 3)
00049 
00050 
00051         cv2.rectangle(image,(maxp2d[0]-5,maxp2d[1]-1), (maxp2d[0]+5, maxp2d[1]+1), (255,255,255), 2)
00052         cv2.rectangle(image,(maxp2d[0]-1,maxp2d[1]-5), (maxp2d[0]+1, maxp2d[1]+5), (255,255,255), 2)
00053         cv2.rectangle(image,(maxp2d[0]-1,maxp2d[1]-1), (maxp2d[0]+1, maxp2d[1]+1), (0,0,0), 1)
00054         cv2.namedWindow("Grasp point")
00055         cv2.imshow("Grasp point", image)
00056         cv2.waitKey(1000)
00057 
00058         basestr="/home/dmartinez/experimentos/ijrr13/exp-SIFT_"
00059         ps=os.popen('ls '+basestr+'*.png | cut -d "_" -f2 | cut -d "." -f1 2>/dev/null')
00060         nums=ps.readlines()
00061         if len(nums):
00062                 num=max([int(x) for x in nums])
00063         else:
00064                 num=-1
00065         cv2.imwrite(basestr+"%04d.png"%(num+1), image)
00066 
00067         # prints
00068         #print res
00069         print 'Res 2D: (' + str(maxp2du) + ',' + str(maxp2dv) + ')'
00070         res = ImagePoint(maxp2du, maxp2dv)
00071 
00072         return res
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 


iri_bow_object_detector
Author(s): dmartinez
autogenerated on Fri Dec 6 2013 22:45:46