Go to the documentation of this file.00001
00002 import roslib; roslib.load_manifest('projector_calibration')
00003 from projector_calibration.msg import Homography
00004 import rospy
00005 from rospy.numpy_msg import numpy_msg
00006 from sensor_msgs.msg import RegionOfInterest
00007 import cv2
00008 import numpy as np
00009
00010 import PySide
00011 from PySide import QtGui, QtCore
00012 from PySide.QtGui import QPalette
00013 import sys
00014 from math import hypot
00015
00016 class Circler(QtGui.QWidget):
00017 H = None
00018 roi = None
00019
00020 def escHandler(self, e):
00021 sys.exit(0)
00022
00023 def initUI(self):
00024
00025 p = QPalette()
00026 p.setColor(QPalette.Background, QtGui.QColor(0,0,0))
00027 self.setPalette(p)
00028 self.showFullScreen()
00029
00030
00031 def homography_cb(self, msg):
00032 self.H = msg.mat.reshape(3,3)
00033
00034 def roi_cb(self, msg):
00035 self.roi = msg
00036
00037 def paintEvent(self, e):
00038 if rospy.is_shutdown(): sys.exit()
00039 if self.roi is not None:
00040 pts = np.float64([[(self.roi.x_offset, self.roi.y_offset)]])
00041 xformed = cv2.perspectiveTransform(pts, self.H)
00042 r = 150
00043 qp = QtGui.QPainter()
00044 qp.begin(self)
00045 color = QtGui.QColor(255,255,255)
00046 qp.setPen(color)
00047 pen = qp.pen()
00048 pen.setWidth(5)
00049 qp.setPen(pen)
00050
00051
00052
00053 rect = QtCore.QRectF(xformed[:,:,1]-r/2, xformed[:,:,0]-r/2, r, r)
00054 qp.drawArc(rect, 0, 360*16)
00055 qp.end()
00056
00057
00058 def __init__(self):
00059 super(Circler, self).__init__()
00060 rospy.Subscriber('homography', numpy_msg(Homography), self.homography_cb)
00061 r = rospy.Rate(10)
00062 while self.H is None:
00063 rospy.loginfo('waiting for homography...')
00064 r.sleep()
00065 print self.H
00066 self.initUI()
00067 rospy.Subscriber('roi', RegionOfInterest, self.roi_cb)
00068 timer = PySide.QtCore.QTimer(self)
00069
00070 timer.timeout.connect(self.update)
00071 timer.start()
00072 sys.exit(app.exec_())
00073 rospy.spin()
00074
00075 if __name__ == '__main__':
00076 rospy.init_node('projector_demo')
00077 app = PySide.QtGui.QApplication(sys.argv)
00078 c = Circler()