コード例 #1
0
 def receive2(self, dt):
     global recv_sock, imageStart, mood_detect, RC4_on, message
     if not imageStart:
         return
     try:
         print("receive")
         mode, stringData = customRecv(recv_sock)
         if mode == 50:
             data = np.fromstring(stringData, dtype='uint8')
             if RC4_on:
                 KeyBytes = RC4.text_to_bytes('key.txt')
                 data = RC4.crypt(data, KeyBytes)
             decimg = cv2.imdecode(data, 1)
             if mood_detect:
                 decimg = fd.face_detect(decimg)
             buf = b''.join(decimg)
             image_texture = Texture.create(size=(640, 480), colorfmt='bgr')
             image_texture.blit_buffer(buf,
                                       colorfmt='bgr',
                                       bufferfmt='ubyte')
             self.texture = image_texture
         elif mode == 10:
             message = stringData.decode()
     except:
         pass
コード例 #2
0
def sender():
    global conn_addr, RC4_on, send_sock
    print("prepare to send\n")
    sleep(2)
    send_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    send_sock.connect(conn_addr)
    encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90]
    ret, frame = capture.read()
    while ret:
        print("send")
        result, imgencode = cv2.imencode('.jpg', np.fliplr(np.flipud(frame)),
                                         encode_param)
        data = np.array(imgencode)
        if RC4_on:
            KeyBytes = RC4.text_to_bytes('key.txt')
            data = RC4.crypt(data, KeyBytes)
        stringData = data.tostring()
        customSend(send_sock, 50, stringData)  # mode = 50 (Video send)
        ret, frame = capture.read()
        sleep(0.1)
    send_sock.close()
    cv2.destroyAllWindows()