예제 #1
0
    def __init__(self, endpoint, modules):
        print modules.keys()
        QWidget.__init__(self)
        print "init"
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)
        #hide kinect interface options
        self.ui.sbTilt.hide()
        self.ui.pbSetLed.hide()
        self.ui.label_4.hide()
        self.ui.cbLedOpt.hide()

        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=2000000")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        print "endpoint", endpoint
        print "prx", self.prx
        print self.mods.keys()
        print "ya"
        self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
        print "yaya"
        self.show()

        self.lalala = 0
        self.maxDepth = 9.0
        self.job()
예제 #2
0
    def __init__(self, endpoint, modules):
        QWidget.__init__(self)
        print "init"
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)
        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=10240")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        print endpoint
        self.proxy = self.mods['RoboCompKinect'].KinectPrx.checkedCast(
            self.prx)
        self.show()
        self.ui.cbLedOpt.addItem("OFF")
        self.ui.cbLedOpt.addItem("GREEN")
        self.ui.cbLedOpt.addItem("RED")
        self.ui.cbLedOpt.addItem("YELLOW")
        self.ui.cbLedOpt.addItem("blinkGREEN")
        self.ui.cbLedOpt.addItem("blinkREDYELLOW")

        self.connect(self.ui.pbSetLed, SIGNAL('clicked()'), self.doSetLed)
        self.connect(self.ui.sbTilt, SIGNAL('valueChanged(double)'),
                     self.doSetTilt)

        self.vector = []
        self.job()
예제 #3
0
	def __init__(self, endpoint, modules):
		print modules.keys()
		QWidget.__init__(self)
		print "init"
		self.ui = Ui_KinectDlg()
		self.ui.setupUi(self)
		#hide kinect interface options
		self.ui.sbTilt.hide()
		self.ui.pbSetLed.hide()
		self.ui.label_4.hide()
		self.ui.cbLedOpt.hide()
		
		self.t = 0.
		arg = sys.argv
		arg.append("--Ice.MessageSizeMax=2000000")
		self.ic = Ice.initialize(arg)
		self.mods = modules
		self.prx = self.ic.stringToProxy(endpoint)
		print "endpoint", endpoint
		print "prx", self.prx
		print self.mods.keys()
		print "ya"
		self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
		print "yaya"
		self.show()
		
		self.lalala = 0
		self.maxDepth = 9.0
		self.job()
예제 #4
0
	def __init__(self, endpoint, modules):
		QWidget.__init__(self)
		print "init"
		self.ui = Ui_KinectDlg()
		self.ui.setupUi(self)
		self.t = 0.
		arg = sys.argv
		arg.append("--Ice.MessageSizeMax=10240")
		self.ic = Ice.initialize(arg)
		self.mods = modules
		self.prx = self.ic.stringToProxy(endpoint)
		print endpoint
		self.proxy = self.mods['RoboCompKinect'].KinectPrx.checkedCast(self.prx)
		self.show()
		self.ui.cbLedOpt.addItem("OFF")
		self.ui.cbLedOpt.addItem("GREEN")
		self.ui.cbLedOpt.addItem("RED")
		self.ui.cbLedOpt.addItem("YELLOW")
		self.ui.cbLedOpt.addItem("blinkGREEN")
		self.ui.cbLedOpt.addItem("blinkREDYELLOW")

		self.connect( self.ui.pbSetLed, SIGNAL('clicked()'), self.doSetLed )
		self.connect( self.ui.sbTilt, SIGNAL('valueChanged(double)'),self.doSetTilt )

		self.vector = []
		self.job()
예제 #5
0
    def __init__(self, endpoint, modules):
        print modules.keys()
        QWidget.__init__(self)
        print "init"
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)

        #hide kinect interface options
        self.ui.sbTilt.hide()
        self.ui.pbSetLed.hide()
        self.ui.label_4.hide()
        self.ui.cbLedOpt.hide()

        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=2000000")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        print endpoint
        print self.mods.keys()
        #self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
        self.proxy = self.mods['RoboCompRGBDBus'].RGBDBusPrx.checkedCast(
            self.prx)
        self.paramsMap = self.proxy.getAllCameraParams()
        self.listCamera = []
        for n in self.paramsMap:
            print 'name Camera: ' + n
            self.listCamera.append(n)

        self.nameActive = self.listCamera.pop()
        self.show()

        #To draw depth image. Maximum device depth. Now in milimeters
        self.maxDepth = 10000.0
        self.mySlot()
        self.myTimer = QTimer()
        self.myTimer.start(10000)
        self.connect(self.myTimer, SIGNAL('timeout()'), self.mySlot)

        self.job()
예제 #6
0
    def __init__(self, endpoint, modules):
        QWidget.__init__(self)
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)
        #hide kinect interface options
        self.ui.sbTilt.hide()
        self.ui.pbSetLed.hide()
        self.ui.label_4.hide()
        self.ui.cbLedOpt.hide()

        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=2000000")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
        self.show()

        self.maxDepth = 90000
        self.method_combo = ""
        self.job()
예제 #7
0
	def __init__(self, endpoint, modules):
		print modules.keys()
		QWidget.__init__(self)
		print "init"
		self.ui = Ui_KinectDlg()
		self.ui.setupUi(self)
		
		#hide kinect interface options
		self.ui.sbTilt.hide()
		self.ui.pbSetLed.hide()
		self.ui.label_4.hide()
		self.ui.cbLedOpt.hide()
		
		self.t = 0.
		arg = sys.argv
		arg.append("--Ice.MessageSizeMax=2000000")
		self.ic = Ice.initialize(arg)
		self.mods = modules
		self.prx = self.ic.stringToProxy(endpoint)
		print endpoint
		print self.mods.keys()
		#self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
		self.proxy = self.mods['RoboCompRGBDBus'].RGBDBusPrx.checkedCast(self.prx)
		self.paramsMap= self.proxy.getAllCameraParams()
		self.listCamera=[]
		for n in self.paramsMap:
			print 'name Camera: '+ n
			self.listCamera.append(n)
		
		self.nameActive=self.listCamera.pop()
		self.show()
		
		#To draw depth image. Maximum device depth. Now in milimeters
		self.maxDepth = 10000.0
		self.mySlot()
		self.myTimer = QTimer()
		self.myTimer.start(10000)
		self.connect(self.myTimer, SIGNAL('timeout()'), self.mySlot)
		
		self.job()
예제 #8
0
class C(QWidget):
    def __init__(self, endpoint, modules):
        QWidget.__init__(self)
        print "init"
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)
        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=10240")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        print endpoint
        self.proxy = self.mods['RoboCompKinect'].KinectPrx.checkedCast(
            self.prx)
        self.show()
        self.ui.cbLedOpt.addItem("OFF")
        self.ui.cbLedOpt.addItem("GREEN")
        self.ui.cbLedOpt.addItem("RED")
        self.ui.cbLedOpt.addItem("YELLOW")
        self.ui.cbLedOpt.addItem("blinkGREEN")
        self.ui.cbLedOpt.addItem("blinkREDYELLOW")

        self.connect(self.ui.pbSetLed, SIGNAL('clicked()'), self.doSetLed)
        self.connect(self.ui.sbTilt, SIGNAL('valueChanged(double)'),
                     self.doSetTilt)

        self.vector = []
        self.job()

    def job(self):
        try:
            self.vector = self.proxy.getDataRGBZinIR(
            )  # imageVector, depthVector, headState, baseState
            if len(self.vector) == 0:
                print 'Error retrieving images!'
        except Ice.Exception:
            traceback.print_exc()

    def paintEvent(self, event=None):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        image = QImage(self.vector[0], 640, 480, QImage.Format_RGB888)
        painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()), image)

        painter.end()
        #painter = None

    def doSetLed(self):
        ledLight = self.textToEnum(self.ui.cbLedOpt.currentText())
        print ledLight
        try:
            self.proxy.setLed(ledLight)
        except Ice.Exception:
            traceback.print_exc()

    def doSetTilt(self):
        try:
            self.proxy.setTilt(self.ui.sbTilt.value())
            self.ui.lcdTilt.display(self.ui.sbTilt.value())
        except Ice.Exception:
            traceback.print_exc()

    def textToEnum(self, pos):
        if (pos == "OFF"):
            return self.mods['RoboCompKinect'].LedOptions.OFF
        elif (pos == "GREEN"):
            return self.mods['RoboCompKinect'].LedOptions.GREEN
        elif (pos == "RED"):
            return self.mods['RoboCompKinect'].LedOptions.RED
        elif (pos == "YELLOW"):
            return self.mods['RoboCompKinect'].LedOptions.YELLOW
        elif (pos == "blinkYELLOW"):
            return self.mods['RoboCompKinect'].LedOptions.blinkYELLOW
        elif (pos == "blinkGREEN"):
            return self.mods['RoboCompKinect'].LedOptions.blinkGREEN
        elif (pos == "blinkREDYELLOW"):
            return self.mods['RoboCompKinect'].LedOptions.blinkREDYELLOW
예제 #9
0
class C(QWidget):
    def __init__(self, endpoint, modules):
        print modules.keys()
        QWidget.__init__(self)
        print "init"
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)

        #hide kinect interface options
        self.ui.sbTilt.hide()
        self.ui.pbSetLed.hide()
        self.ui.label_4.hide()
        self.ui.cbLedOpt.hide()

        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=2000000")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        print endpoint
        print self.mods.keys()
        #self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
        self.proxy = self.mods['RoboCompRGBDBus'].RGBDBusPrx.checkedCast(
            self.prx)
        self.paramsMap = self.proxy.getAllCameraParams()
        self.listCamera = []
        for n in self.paramsMap:
            print 'name Camera: ' + n
            self.listCamera.append(n)

        self.nameActive = self.listCamera.pop()
        self.show()

        #To draw depth image. Maximum device depth. Now in milimeters
        self.maxDepth = 10000.0
        self.mySlot()
        self.myTimer = QTimer()
        self.myTimer.start(10000)
        self.connect(self.myTimer, SIGNAL('timeout()'), self.mySlot)

        self.job()

    def mySlot(self):
        if (len(self.listCamera) == 0):
            print "refill"
            for n in self.paramsMap:
                self.listCamera.append(n)
        self.nameActive = self.listCamera.pop()

    def job(self):
        try:
            print 'name Camera Active: ' + self.nameActive
            self.cameralist = [self.nameActive]
            self.imagemap = self.proxy.getImages(self.cameralist)
            self.ui.nameRGBD.setText('RGBD name: ' + self.nameActive)

            self.depth = self.imagemap[self.nameActive].depthImage
            self.color = self.imagemap[self.nameActive].colorImage
            if (len(self.color) == 0) or (len(self.depth) == 0):
                print 'Error retrieving images!'
        except Ice.Exception:
            traceback.print_exc()

    def paintEvent(self, event=None):
        print "paint Event"
        print len(self.color)
        print len(self.depth)
        print 3 * ((640 * 480) / 2)
        if (len(self.color) == 3 * 640 * 480 or len(self.depth) == 640 * 480):
            w = 640
            h = 480

        elif (len(self.color) == 3 * 320 * 240
              or len(self.depth) == (640 * 480) / 2):
            w = 320
            h = 240
        else:
            print 'we shall not paint!'
            return
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        v = ''
        for i in range(len(self.depth)):
            ascii = 0
            try:
                ascii = int((self.depth[i] / self.maxDepth) * 256)
            except:
                pass
            if ascii > 255: ascii = 255
            v += chr(ascii)
        image = QImage(self.color, w, h, QImage.Format_RGB888)
        imageGrey = QImage(v, w, h, QImage.Format_Indexed8)
        for i in range(256):
            imageGrey.setColor(i, QColor(i, i, i).rgb())
        painter.drawImage(QPointF(self.ui.frameRGB.x(), self.ui.frameRGB.y()),
                          image)
        painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()),
                          imageGrey)
        painter.end()
        painter = None
예제 #10
0
class C(QWidget):
    def __init__(self, endpoint, modules):
        QWidget.__init__(self)
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)
        #hide kinect interface options
        self.ui.sbTilt.hide()
        self.ui.pbSetLed.hide()
        self.ui.label_4.hide()
        self.ui.cbLedOpt.hide()

        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=2000000")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
        self.show()

        self.maxDepth = 90000
        self.method_combo = ""
        self.job()

    def job(self):
        self.method_combo = unicode(self.ui.method_combobox.currentText())
        if "getData" in self.method_combo:
            try:
                self.color, self.depth, self.headState, self.baseState = self.proxy.getData(
                )
                #print 'c', len(self.color)
                #print 'd', len(self.depth)
                if (len(self.color) == 0) or (len(self.depth) == 0):
                    print 'Error retrieving images!'
            except Ice.Exception:
                traceback.print_exc()
        elif "getImage" in self.method_combo:
            try:
                self.color, self.depth, _, self.headState, self.baseState = self.proxy.getImage(
                )
                #print 'c', len(self.color)
                #print 'd', len(self.depth)
                if (len(self.color) == 0) or (len(self.depth) == 0):
                    print 'Error retrieving images!'
            except Ice.Exception:
                traceback.print_exc()
        elif "getRGB" in self.method_combo:
            try:
                self.color, self.headState, self.baseState = self.proxy.getRGB(
                )
                #print 'c', len(self.color)
                #print 'd', len(self.depth)
                if (len(self.color) == 0) or (len(self.depth) == 0):
                    print 'Error retrieving images!'
            except Ice.Exception:
                traceback.print_exc()
        elif "getDepth" in self.method_combo:
            try:
                self.depth, self.headState, self.baseState = self.proxy.getDepth(
                )
                #print 'c', len(self.color)
                #print 'd', len(self.depth)
                if (len(self.color) == 0) or (len(self.depth) == 0):
                    print 'Error retrieving images!'
            except Ice.Exception:
                traceback.print_exc()

    def paintEvent(self, event=None):
        color_image_height = 0
        color_image_width = 0
        depth_image_height = 0
        depth_image_width = 0
        if "getData" in self.method_combo or "getImage" in self.method_combo or "getDepth" in self.method_combo:
            if (len(self.depth) == 640 * 480):
                depth_image_width = 640
                depth_image_height = 480
            elif (len(self.depth) == 320 * 240):
                depth_image_width = 320
                depth_image_height = 240
            # print "color", len(self.color), "depth", len(self.depth)
            else:
                print 'Undetermined Depth image size: we shall not paint! %d' % (
                    len(self.depth))
                return
        if "getData" in self.method_combo:
            # print type(self.color)
            if (len(self.color) == 3 * 640 * 480):
                color_image_width = 640
                color_image_height = 480
            elif (len(self.color) == 3 * 320 * 240):
                color_image_width = 320
                color_image_height = 240
                #print "color", len(self.color), "depth", len(self.depth)
            else:
                print 'Undetermined Color image size: we shall not paint! %d' % (
                    len(self.color))
                return
        elif "getRGB" in self.method_combo or "getImage" in self.method_combo:
            new_color = ''
            if (len(self.color) == 640 * 480):
                color_image_width = 640
                color_image_height = 480
            elif (len(self.color) == 320 * 240):
                color_image_width = 320
                color_image_height = 240
            else:
                print 'Undetermined Color image size in getRGB: we shall not paint! %d' % (
                    len(self.color))
                return
            for color_struct in self.color:
                new_color += chr(color_struct.red)
                new_color += chr(color_struct.green)
                new_color += chr(color_struct.blue)
            self.color = new_color

        if depth_image_height != color_image_height or depth_image_width != color_image_width:
            print "Warning: Depth (%d,%d) and Color(%d,%d) sizes mismatch" % (
                depth_image_width, depth_image_height, color_image_width,
                color_image_height)

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        if depth_image_width != 0 and depth_image_height != 0:
            # Interpolate values from depth float arrray to 0-255 integers
            depth = np.array(self.depth, dtype=np.float32)
            depth_min = np.min(depth)
            depth_max = np.max(depth)
            if depth_max != depth_min and depth_max > 0:
                depth = np.interp(depth, [depth_min, depth_max], [255.0, 0.0],
                                  right=0.0,
                                  left=0.0)
            depth = depth.astype(np.uint8)

            # Reshape to grayscale matrix
            depth = depth.reshape(depth_image_height, depth_image_width)

            # Convert to
            if depth.dtype == np.uint8:
                if len(depth.shape) == 2:
                    gray_color_table = [qRgb(i, i, i) for i in range(256)]
                    imageGrey = QImage(depth.data, depth.shape[1],
                                       depth.shape[0], depth.strides[0],
                                       QImage.Format_Indexed8)
                    imageGrey.setColorTable(gray_color_table)
                else:
                    print("Wrong depth matrix format: Shape %s" %
                          (depth.shape))
            # imageGrey = QImage(depth, depth_image_width, depth_image_height, QImage.Format_Mono)
            # for i in range(256):
            # 	imageGrey.setColor(i, QColor(i, i, i).rgb())
            painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()),
                              imageGrey)
        #print 'mean', float(m)/t
        if color_image_width != 0 and color_image_height != 0:
            image = QImage(self.color, color_image_width, color_image_height,
                           QImage.Format_RGB888)
            #image.save("images/image"+str(self.lalala)+'.png')
            painter.drawImage(
                QPointF(self.ui.frameRGB.x(), self.ui.frameRGB.y()), image)

        painter.end()
예제 #11
0
class C(QWidget):
    def __init__(self, endpoint, modules):
        print modules.keys()
        QWidget.__init__(self)
        print "init"
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)
        #hide kinect interface options
        self.ui.sbTilt.hide()
        self.ui.pbSetLed.hide()
        self.ui.label_4.hide()
        self.ui.cbLedOpt.hide()

        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=2000000")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        print "endpoint", endpoint
        print "prx", self.prx
        print self.mods.keys()
        print "ya"
        self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
        print "yaya"
        self.show()

        self.maxDepth = 9.0
        self.job()

    def job(self):
        print "hola"
        try:
            self.color, self.depth, self.headState, self.baseState = self.proxy.getData(
            )
            #print len(self.color)
            if (len(self.color) == 0) or (len(self.depth) == 0):
                print 'Error retrieving images!'
        except Ice.Exception:
            traceback.print_exc()

    def paintEvent(self, event=None):
        if (len(self.color) == 3 * 640 * 480) and (len(self.depth)
                                                   == 640 * 480):
            width = 640
            height = 480
        elif (len(self.color) == 3 * 320 * 240) and (len(self.depth)
                                                     == 320 * 240):
            width = 320
            height = 240
            #print "color", len(self.color), "depth", len(self.depth)
        else:
            print 'we shall not paint!'
            return

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        v = ''
        for i in range(len(self.depth)):
            ascii = 0
            try:
                ascii = int(255. - 255. *
                            (self.depth[i] / self.maxDepth / 1000.))
                if ascii > 255: ascii = 255
                if ascii < 0: ascii = 0
            except:
                pass
            if ascii > 255: ascii = 255
            v += chr(ascii)
        image = QImage(self.color, width, height, QImage.Format_RGB888)
        imageGrey = QImage(v, width, height, QImage.Format_Indexed8)
        for i in range(256):
            imageGrey.setColor(i, QColor(i, i, i).rgb())
        painter.drawImage(QPointF(self.ui.frameRGB.x(), self.ui.frameRGB.y()),
                          image)
        painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()),
                          imageGrey)
        painter.end()
예제 #12
0
class C(QWidget):
    def __init__(self, endpoint, modules):
        QWidget.__init__(self)
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)
        #hide kinect interface options
        self.ui.sbTilt.hide()
        self.ui.pbSetLed.hide()
        self.ui.label_4.hide()
        self.ui.cbLedOpt.hide()

        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=2000000")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        self.proxy = self.mods[
            'RoboCompCameraRGBDSimple'].CameraRGBDSimplePrx.checkedCast(
                self.prx)
        self.show()

        self.maxDepth = 90000
        self.method_combo = ""
        self.job()

    def job(self):
        self.method_combo = str(self.ui.method_combobox.currentText())
        if "getData" in self.method_combo:
            try:
                self.color, self.depth = self.proxy.getAll()
                if (len(self.color.image) == 0) or (len(self.depth.depth)
                                                    == 0):
                    print('Error retrieving images!')
            except Ice.Exception:
                traceback.print_exc()
        elif "getImage" in self.method_combo:
            try:
                self.color = self.proxy.getImage()
                if (len(self.color.image) == 0):
                    print('Error retrieving images!')
            except Ice.Exception:
                traceback.print_exc()
        elif "getDepth" in self.method_combo:
            try:
                self.depth = self.proxy.getDepth()
                if (len(self.depth.depth) == 0):
                    print('Error retrieving images!')
            except Ice.Exception:
                traceback.print_exc()

    def paintEvent(self, event=None):
        color_image_height = 0
        color_image_width = 0
        depth_image_height = 0
        depth_image_width = 0
        # print "Paint event "+str(len(self.depth))+" "+str(type(self.depth))
        if "getData" in self.method_combo:
            depth_image_width = self.depth.width
            depth_image_height = self.depth.height
            color_image_width = self.color.width
            color_image_height = self.color.height
        if "getDepth" in self.method_combo:
            depth_image_width = self.depth.width
            depth_image_height = self.depth.height
        if "getImage" in self.method_combo:
            color_image_width = self.color.width
            color_image_height = self.color.height

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        if depth_image_width != 0 and depth_image_height != 0:
            depth = np.asanyarray(self.depth.depth, dtype=np.float32)
            depth_min = np.min(depth)
            depth_max = np.max(depth)
            if depth_max != depth_min and depth_max > 0:
                depth = np.interp(depth, [depth_min, depth_max], [255.0, 0.0],
                                  right=0.0,
                                  left=0.0)
            depth = depth.astype(np.uint8)

            # Reshape to grayscale matrix
            depth = depth.reshape(depth_image_height, depth_image_width)

            # Convert to
            if depth.dtype == np.uint8:
                if len(depth.shape) == 2:
                    gray_color_table = [qRgb(i, i, i) for i in range(256)]
                    imageGrey = QImage(depth.data, depth.shape[1],
                                       depth.shape[0], depth.strides[0],
                                       QImage.Format_Indexed8)
                    imageGrey.setColorTable(gray_color_table)
                else:
                    print("Wrong depth matrix format: Shape %s" %
                          (depth.shape))
            painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()),
                              imageGrey)
        #print 'mean', float(m)/t
        if color_image_width != 0 and color_image_height != 0:
            image = QImage(self.color.image, color_image_width,
                           color_image_height, QImage.Format_RGB888)
            #image.save("images/image"+str(self.lalala)+'.png')
            painter.drawImage(
                QPointF(self.ui.frameRGB.x(), self.ui.frameRGB.y()), image)

        painter.end()
예제 #13
0
class C(QWidget):
	def __init__(self, endpoint, modules):
		print modules.keys()
		QWidget.__init__(self)
		print "init"
		self.ui = Ui_KinectDlg()
		self.ui.setupUi(self)
		#hide kinect interface options
		self.ui.sbTilt.hide()
		self.ui.pbSetLed.hide()
		self.ui.label_4.hide()
		self.ui.cbLedOpt.hide()
		
		self.t = 0.
		arg = sys.argv
		arg.append("--Ice.MessageSizeMax=2000000")
		self.ic = Ice.initialize(arg)
		self.mods = modules
		self.prx = self.ic.stringToProxy(endpoint)
		print "endpoint", endpoint
		print "prx", self.prx
		print self.mods.keys()
		print "ya"
		self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
		print "yaya"
		self.show()
		
		self.lalala = 0
		self.maxDepth = 9.0
		self.job()

	def job(self):
		print "hola"
		try:
			self.color, self.depth, self.headState, self.baseState = self.proxy.getData()
			#print len(self.color)
			if (len(self.color) == 0) or (len(self.depth) == 0):
				print 'Error retrieving images!'
		except Ice.Exception:
			traceback.print_exc()

	def paintEvent(self, event=None):
		if (len(self.color) == 3*640*480) and (len(self.depth) == 640*480):
			width = 640
			height = 480
		elif (len(self.color) == 3*320*240) and (len(self.depth) == 320*240):
			width = 320
			height = 240
			#print "color", len(self.color), "depth", len(self.depth)
		else:
			print 'we shall not paint!'
			return
		
		painter = QPainter(self)
		painter.setRenderHint(QPainter.Antialiasing, True)
		
		v = ''
		for i in range(len(self.depth)):
			ascii = 0
			try:
				ascii = int(255.-255.*(self.depth[i] / self.maxDepth / 1000. ) )
				if ascii > 255: ascii = 255
				if ascii < 0: ascii = 0
			except:
				pass
			if ascii > 255: ascii = 255
			v += chr(ascii)
		image = QImage(self.color, width, height, QImage.Format_RGB888)
		self.lalala+=1
		image.save("images/image"+str(self.lalala)+'.png')
		print "lalala: ", str(self.lalala)
		imageGrey = QImage(v, width, height, QImage.Format_Indexed8)
		for i in range(256):
			imageGrey.setColor(i, QColor(i,i,i).rgb())
		painter.drawImage(QPointF(self.ui.frameRGB.x(), self.ui.frameRGB.y()), image)
		painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()), imageGrey)
		painter.end()
예제 #14
0
class C(QWidget):
	def __init__(self, endpoint, modules):
		QWidget.__init__(self)
		print "init"
		self.ui = Ui_KinectDlg()
		self.ui.setupUi(self)
		self.t = 0.
		arg = sys.argv
		arg.append("--Ice.MessageSizeMax=10240")
		self.ic = Ice.initialize(arg)
		self.mods = modules
		self.prx = self.ic.stringToProxy(endpoint)
		print endpoint
		self.proxy = self.mods['RoboCompKinect'].KinectPrx.checkedCast(self.prx)
		self.show()
		self.ui.cbLedOpt.addItem("OFF")
		self.ui.cbLedOpt.addItem("GREEN")
		self.ui.cbLedOpt.addItem("RED")
		self.ui.cbLedOpt.addItem("YELLOW")
		self.ui.cbLedOpt.addItem("blinkGREEN")
		self.ui.cbLedOpt.addItem("blinkREDYELLOW")

		self.connect( self.ui.pbSetLed, SIGNAL('clicked()'), self.doSetLed )
		self.connect( self.ui.sbTilt, SIGNAL('valueChanged(double)'),self.doSetTilt )

		self.vector = []
		self.job()

	def job(self):
		try:
			self.vector = self.proxy.getDataRGBZinIR() # imageVector, depthVector, headState, baseState
			if len(self.vector) == 0:
				print 'Error retrieving images!'
		except Ice.Exception:
			traceback.print_exc()


	def paintEvent(self, event=None):
		painter = QPainter(self)
		painter.setRenderHint(QPainter.Antialiasing, True)

		image = QImage(self.vector[0], 640, 480, QImage.Format_RGB888)
		painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()), image)

		painter.end()
		#painter = None

	def doSetLed(self):
		ledLight = self.textToEnum(self.ui.cbLedOpt.currentText())
		print ledLight
		try:
			self.proxy.setLed( ledLight )
		except Ice.Exception:
			traceback.print_exc()
			
	def doSetTilt(self):
	   try:
		 self.proxy.setTilt(self.ui.sbTilt.value())
		 self.ui.lcdTilt.display(self.ui.sbTilt.value())
	   except Ice.Exception:
		 traceback.print_exc()
		 
	def textToEnum(self,pos):
		if(pos == "OFF"):
				return self.mods['RoboCompKinect'].LedOptions.OFF
		elif(pos == "GREEN"):
				return self.mods['RoboCompKinect'].LedOptions.GREEN
		elif(pos == "RED"):
				return self.mods['RoboCompKinect'].LedOptions.RED
		elif(pos == "YELLOW"):
				return self.mods['RoboCompKinect'].LedOptions.YELLOW
		elif(pos == "blinkYELLOW"):
				return self.mods['RoboCompKinect'].LedOptions.blinkYELLOW
		elif(pos == "blinkGREEN"):
				return self.mods['RoboCompKinect'].LedOptions.blinkGREEN
		elif(pos == "blinkREDYELLOW"):
				return self.mods['RoboCompKinect'].LedOptions.blinkREDYELLOW
예제 #15
0
class C(QWidget):
	def __init__(self, endpoint, modules):
		print modules.keys()
		QWidget.__init__(self)
		print "init"
		self.ui = Ui_KinectDlg()
		self.ui.setupUi(self)
		
		#hide kinect interface options
		self.ui.sbTilt.hide()
		self.ui.pbSetLed.hide()
		self.ui.label_4.hide()
		self.ui.cbLedOpt.hide()
		
		self.t = 0.
		arg = sys.argv
		arg.append("--Ice.MessageSizeMax=2000000")
		self.ic = Ice.initialize(arg)
		self.mods = modules
		self.prx = self.ic.stringToProxy(endpoint)
		print endpoint
		print self.mods.keys()
		#self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
		self.proxy = self.mods['RoboCompRGBDBus'].RGBDBusPrx.checkedCast(self.prx)
		self.paramsMap= self.proxy.getAllCameraParams()
		self.listCamera=[]
		for n in self.paramsMap:
			print 'name Camera: '+ n
			self.listCamera.append(n)
		
		self.nameActive=self.listCamera.pop()
		self.show()
		
		#To draw depth image. Maximum device depth. Now in milimeters
		self.maxDepth = 10000.0
		self.mySlot()
		self.myTimer = QTimer()
		self.myTimer.start(10000)
		self.connect(self.myTimer, SIGNAL('timeout()'), self.mySlot)
		
		self.job()
		
	def mySlot (self):
		if (len(self.listCamera) ==0):
			print "refill" 
			for n in self.paramsMap:
				self.listCamera.append(n)
		self.nameActive=self.listCamera.pop()

	def job(self):
		try:
			print 'name Camera Active: '+ self.nameActive
			self.cameralist = [self.nameActive]
			self.imagemap = self.proxy.getImages(self.cameralist)
			self.ui.nameRGBD.setText('RGBD name: ' + self.nameActive)
			
			self.depth =self.imagemap[self.nameActive].depthImage
			self.color =self.imagemap[self.nameActive].colorImage
			if (len(self.color) == 0) or (len(self.depth) == 0):
				print 'Error retrieving images!'
		except Ice.Exception:
			traceback.print_exc()

	def paintEvent(self, event=None):
		print "paint Event"	
		print len(self.color)
		print len(self.depth)
		print 3*( (640*480)/2)
		if (len(self.color) == 3*640*480 or len(self.depth) == 640*480):
			w=640
			h=480
		elif (len(self.color) == 3*320*240 or len(self.depth) == (640*480)/2):
			w=320
			h=240
		else:
			print 'we shall not paint!'
			return	
		painter = QPainter(self)
		painter.setRenderHint(QPainter.Antialiasing, True)
		
		v = ''
		for i in range(len(self.depth)):
			ascii = 0
			try:
				ascii = int((self.depth[i] / self.maxDepth ) * 256)
			except:
				pass
			if ascii > 255: ascii = 255
			v += chr(ascii)
		image = QImage(self.color, w, h, QImage.Format_RGB888)
		imageGrey = QImage(v, w, h, QImage.Format_Indexed8)
		for i in range(256):
			imageGrey.setColor(i, QColor(i,i,i).rgb())
		painter.drawImage(QPointF(self.ui.frameRGB.x(), self.ui.frameRGB.y()), image)
		painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()), imageGrey)
		painter.end()
		painter = None
예제 #16
0
파일: rgbd.py 프로젝트: Kmayankkr/rcmanager
class C(QWidget):
    def __init__(self, endpoint, modules):
        QWidget.__init__(self)
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)
        #hide kinect interface options
        self.ui.sbTilt.hide()
        self.ui.pbSetLed.hide()
        self.ui.label_4.hide()
        self.ui.cbLedOpt.hide()

        self.t = 0.
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=2000000")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        self.proxy = self.mods['RoboCompRGBD'].RGBDPrx.checkedCast(self.prx)
        self.show()

        self.maxDepth = 90000
        self.job()

    def job(self):
        try:
            self.color, self.depth, self.headState, self.baseState = self.proxy.getData(
            )
            #print 'c', len(self.color)
            #print 'd', len(self.depth)
            if (len(self.color) == 0) or (len(self.depth) == 0):
                print 'Error retrieving images!'
        except Ice.Exception:
            traceback.print_exc()

    def paintEvent(self, event=None):
        if (len(self.color) == 3 * 640 * 480) and (len(self.depth)
                                                   == 640 * 480):
            width = 640
            height = 480
        elif (len(self.color) == 3 * 320 * 240) and (len(self.depth)
                                                     == 320 * 240):
            width = 320
            height = 240
            #print "color", len(self.color), "depth", len(self.depth)
        else:
            print 'we shall not paint!'
            return

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        v = ''
        m = 0
        t = 0
        for i in range(len(self.depth)):
            ascii = 0
            try:
                ascii = int(128. - (255. / self.maxDepth) * self.depth[i])
                if ascii > 255: ascii = 255
                if ascii < 0: ascii = 0
                #print type(self.depth[i])
                if fabs(self.depth[i]) > 0.00001: print self.depth[i]
            except:
                pass
            if ascii > 255: ascii = 255
            if ascii < 0: ascii = 0
            v += chr(ascii)
            t = t + 1
            m = m + float(self.depth[i])
        #print 'mean', float(m)/t
        image = QImage(self.color, width, height, QImage.Format_RGB888)
        #image.save("images/image"+str(self.lalala)+'.png')
        imageGrey = QImage(v, width, height, QImage.Format_Indexed8)
        for i in range(256):
            imageGrey.setColor(i, QColor(i, i, i).rgb())
        painter.drawImage(QPointF(self.ui.frameRGB.x(), self.ui.frameRGB.y()),
                          image)
        painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()),
                          imageGrey)
        painter.end()
예제 #17
0
파일: rgbd.py 프로젝트: krips89/robocomp
class C(QWidget):
    def __init__(self, endpoint, modules):
        print modules.keys()
        QWidget.__init__(self)
        print "init"
        self.ui = Ui_KinectDlg()
        self.ui.setupUi(self)
        # hide kinect interface options
        self.ui.sbTilt.hide()
        self.ui.pbSetLed.hide()
        self.ui.label_4.hide()
        self.ui.cbLedOpt.hide()

        self.t = 0.0
        arg = sys.argv
        arg.append("--Ice.MessageSizeMax=2000000")
        self.ic = Ice.initialize(arg)
        self.mods = modules
        self.prx = self.ic.stringToProxy(endpoint)
        print endpoint
        print self.mods.keys()
        self.proxy = self.mods["RoboCompRGBD"].RGBDPrx.checkedCast(self.prx)
        self.show()

        self.maxDepth = 9.0
        self.job()

    def job(self):
        try:
            self.color, self.depth, self.headState, self.baseState = self.proxy.getData()
            print len(self.color)
            if (len(self.color) == 0) or (len(self.depth) == 0):
                print "Error retrieving images!"
        except Ice.Exception:
            traceback.print_exc()

    def paintEvent(self, event=None):
        if (len(self.color) != 3 * 640 * 480) or (len(self.depth) != 640 * 480):
            # print 'we shall not paint!'
            return

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        v = ""
        for i in range(len(self.depth)):
            ascii = 0
            try:
                ascii = int(255.0 - 255.0 * (self.depth[i] / self.maxDepth / 1000.0))
                if ascii > 255:
                    ascii = 255
                if ascii < 0:
                    ascii = 0
            except:
                pass
            if ascii > 255:
                ascii = 255
            v += chr(ascii)
        image = QImage(self.color, 640, 480, QImage.Format_RGB888)
        imageGrey = QImage(v, 640, 480, QImage.Format_Indexed8)
        for i in range(256):
            imageGrey.setColor(i, QColor(i, i, i).rgb())
        painter.drawImage(QPointF(self.ui.frameRGB.x(), self.ui.frameRGB.y()), image)
        painter.drawImage(QPointF(self.ui.frame.x(), self.ui.frame.y()), imageGrey)
        painter.end()