Esempio n. 1
0
    def process_one(self):
        if not self.to_process:
            return

        # input is an ascii string.
        input_str = self.to_process.pop(0)

        # convert it to a pil image
        input_img = base64_to_pil_image(input_str)

        open_cv_image = numpy.array(input_img)
        open_cv_image = open_cv_image[:, :, ::-1].copy()

        output_img_cv = self.makeup_artist.apply_makeup(open_cv_image)

        img = cv2.cvtColor(output_img_cv, cv2.COLOR_BGR2RGB)
        output_img = Image.fromarray(img)

        ################## where the hard work is done ############
        # # output_img is an PIL image
        # output_img = self.makeup_artist.apply_makeup(input_img)

        # output_str is a base64 string in ascii
        output_str = pil_image_to_base64(output_img)

        # convert eh base64 string in ascii to base64 string in _bytes_
        self.to_output.append(binascii.a2b_base64(output_str))
Esempio n. 2
0
 def insert_img(self):
     try:
         img_path = QFileDialog.getOpenFileName(self, 'Select Image',"",'Images(*.png)')
         kof = utils.pil_image_to_base64(img_path[0])
         self.ui.textEdit.insertHtml('<img src="data:image/png;base64,'+''+ kof+' ,alt=Red Dot'+'/>')
     except FileNotFoundError:
         print('File Not Found')
    def process_one(self):
        if not self.to_process:
            return

        # input is an ascii string.
        input_str = self.to_process.pop(0)

        # convert it to a pil image
        input_img = base64_to_pil_image(input_str)

        # output_img is an PIL image
        output_img = input_img

        # output_str is a base64 string in ascii
        output_str = pil_image_to_base64(output_img)

        # convert the base64 string in ascii to base64 string in _bytes_
        self.to_output.append(binascii.a2b_base64(output_str))
Esempio n. 4
0
    def process_one(self):
        if not self.to_process:
            return

        # input is an ascii string. 
        input_str = self.to_process.pop(0)

        # convert it to a pil image
        input_img = base64_to_pil_image(input_str)

        ################## where the hard work is done ############
        # output_img is an PIL image
        output_img = self.makeup_artist.apply_makeup(input_img)

        # output_str is a base64 string in ascii
        output_str = pil_image_to_base64(output_img)

        # convert eh base64 string in ascii to base64 string in _bytes_
        self.to_output.append(binascii.a2b_base64(output_str))
    def process_one(self):
        if not self.to_process or not self.volume:
            print("empty list")
            return
        # input is an ascii string.
        input_str = self.to_process.pop(0)

        # convert it to a pil image
        input_img = base64_to_pil_image(input_str)
        v = self.volume.pop(0)

        ################## where the hard work is done ############
        # output_img is an PIL image
        output_img, self.ikon = self.makeup_artist.apply_makeup(
            input_img, self.ikon, v)

        # output_str is a base64 string in ascii
        output_str = pil_image_to_base64(output_img)

        # convert eh base64 string in ascii to base64 string in _bytes_
        self.to_output.append(binascii.a2b_base64(output_str))
        print("to output list: {}".format(len(self.to_output)))
Esempio n. 6
0
    def process_one(self):
        if not self.to_process:
            return

        # input is an ascii string.
        input_str = self.to_process.pop(0)

        # convert it to a pil image
        input_img = base64_to_pil_image(input_str)

        # frame = np.array(input_img)
        print("Type of input image", input_img)
        data1 = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
        size = (224, 224)
        image = ImageOps.fit(input_img, size, Image.ANTIALIAS)
        image_array = np.asarray(image)
        normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
        data1[0] = normalized_image_array

        ################## where the hard work is done ############
        # output_img is an PIL image
        #image_array = cv2.resize(image_array,(300,150))
        #cv2.imshow("frame",image_array)
        # ret, jpeg = cv2.imencode('.jpg', image_array)
        # image_array = cv2.resize(jpeg, (300, 150))
        PIL_image = Image.fromarray(
            np.uint8(image_array)).convert('RGB').resize(size=(300, 150))
        b = BytesIO()
        PIL_image.save(b, format="jpeg")
        PIL_image = Image.open(b)
        #Image.open(BytesIO(base64.b64decode(base64_img))
        #output_img = self.makeup_artist.apply_makeup(jpeg)

        # output_str is a base64 string in ascii
        output_str = pil_image_to_base64(PIL_image)

        # convert eh base64 string in ascii to base64 string in _bytes_
        self.to_output.append(binascii.a2b_base64(output_str))
Esempio n. 7
0
    def process_one(self):
        if not self.to_process:
            return

        # input is an ascii string.
        input_str = self.to_process.pop(0)

        # convert it to a pil image
        input_img = base64_to_pil_image(input_str)

        ################## where the hard work is done ############
        # output_img is an PIL image
        output_img = self.makeup_artist.apply_makeup(input_img)
        frame = cv2.cvtColor(np.array(output_img), cv2.COLOR_RGB2BGR)
        cv2.resize(frame, (400, 560), interpolation=cv2.INTER_AREA)

        im = cv2.imread("newmask.png")

        # cv2.rectangle(image, (400, 300), (700, 500), (178, 190, 181), 5)

        # frame = cv2.flip(opencvImage, 2)

        gaze.refresh(frame)

        frame, x, y = gaze.annotated_frame()
        text = ""

        # cv2.putText(frame, text, (90, 60), cv2.FONT_HERSHEY_DUPLEX, 1.6, (147, 58, 31), 2)

        left_pupil = gaze.pupil_left_coords()

        right_pupil = gaze.pupil_right_coords()
        print(right_pupil, left_pupil)

        points_cnt = (x, y)

        # print(points_cnt)
        if left_pupil and right_pupil != None:
            a = left_pupil
            b = right_pupil
            c = points_cnt
            # dist = [(a - c) ** 2 for a, c in zip(a, c)]
            # dist = math.sqrt(sum(dist))
            # print("new method",dist)

            dst_left = distance.euclidean(a, c)
            mm = 0.26458333
            dist_left_mm = (dst_left * mm) + 20

            # print(dist_left_mm)
            print("left:::", dist_left_mm)
            dst_right = distance.euclidean(b, c)
            # print(dst_right)
            # print(dst_left)

            dist_right_mm = (dst_right * mm) + 20
            total_pd = dist_right_mm + dist_left_mm
            print("total::", total_pd)
            print("right::", dist_right_mm)

            cv2.putText(frame, "Left PD:  " + str(dist_left_mm) + 'mm',
                        (80, 135), cv2.FONT_HERSHEY_DUPLEX, 0.9, (0, 0, 255),
                        1)
            cv2.putText(frame, "Right PD: " + str(dist_right_mm) + 'mm',
                        (85, 175), cv2.FONT_HERSHEY_DUPLEX, 0.9, (0, 0, 255),
                        1)
            # cv2.putText(frame, "Total PD: " + str(total_pd) + 'mm', (85, 200), cv2.FONT_HERSHEY_DUPLEX, 0.9,
            #             (0, 0, 255), 1)
        # print(frame.shape[1::-1])
        im = cv2.resize(im, frame.shape[1::-1], interpolation=cv2.INTER_AREA)
        dst = cv2.addWeighted(frame, 0.5, im, 0.5, 0)

        # cv2.imshow("Frame",dst)
        # cv2.waitKey(1)
        ##Convert opencv output to pillow image
        img = cv2.cvtColor(dst, cv2.COLOR_BGR2RGB)
        im_pil = Image.fromarray(img)

        # output_str is a base64 string in ascii
        output_str = pil_image_to_base64(im_pil)

        # convert eh base64 string in ascii to base64 string in _bytes_
        self.to_output.append(binascii.a2b_base64(output_str))