Пример #1
0
    def run(self):
        # self.logger.info(str(self.name) + '[' + str(self.pid) + '] started on ' + str(self.host) + ':' + str(self.port) + ', Daemon: ' + str(self.daemon))
        # pub = zmq.PubBase64((self.host, self.port))
        pub = zmq.Pub((self.host, self.port), hwm=100)
        camera = Camera('pi')
        # 		camera.init(cameraNumber=self.camera_num, win=(640, 480))
        camera.init(win=(640, 480))

        # self.logger.info('Openned camera: ' + str(self.camera_num))

        try:
            while True:
                ret, frame = camera.read()

                # 				jpeg = cv2.imencode('.jpg', frame)[1]  # jpeg compression
                # 				msg = Msg.Image(jpeg)
                if ret:
                    msg = Msg.Image()
                    msg.img = frame
                    pub.pub('image_color', msg)
                    # print '[*] frame: %d k   jpeg: %d k'%(frame.size/1000,len(jpeg)/1000)
# 					time.sleep(0.01)
                else:
                    print('dropped image')

        except KeyboardInterrupt:
            print('Ctl-C ... exiting')
            return
Пример #2
0
def pygecko_image():
	frame = np.random.randint(0, 255, size=(640, 480))
	jpeg = cv2.imencode('.jpg', frame)[1]
	b64 = base64.b64encode(jpeg)
	m = Msg.Image(b64)
	m = Msg.serialize(m)
	m = Msg.deserialize(m)
	# print m
	ii = base64.b64decode(m['image'])
	ii = np.fromstring(ii, dtype=np.uint8)
	cv2.imdecode(ii, 0)
Пример #3
0
    def run(self):
        print('Publishing ball {}:{}'.format('0.0.0.0', '9000'))
        pub_ball = zmq.Pub(('0.0.0.0', 9000))
        print('Publishing image_color {}:{}'.format('0.0.0.0', '9010'))
        pub_image = zmq.Pub(('0.0.0.0', 9010))

        try:
            while True:
                ret, frame = self.camera.read()
                msg = Msg.Image()
                msg.img = frame
                pub_image.pub('image_color', msg)

                width, height = frame.shape[:2]
                center, radius = self.balltracker.find(frame)
                if center and radius > 10:
                    x, y = center
                    xx = x - width / 2
                    yy = y - height / 2

                    msg = Msg.Vector()
                    msg.set(xx, yy, 0)
                    pub_ball.pub('ball', msg)

                faces = self.face.find(frame)
                if len(faces) > 0:
                    print('found a face!', faces, type(faces))
                    # msg = Msg.Array()
                    # msg.array = [[1,2,3,4], [4,5,6,7]]
                    # msg.array = list(faces)
                    # msg.array = faces
                    # print('msg >>', msg, type(msg.array))
                    # pub_ball.pub('faces', msg)
                    # print(msg)

                # sleep(0.01)

        except KeyboardInterrupt:
            print('Ctl-C ... exiting')
            return