Beispiel #1
0
 def test_animated_image(self):
     frames = []
     generated_frames = []
     expected = []
     
     
     for i in self.frame_count:
         generated_frames.append(cv2.imread("test_2_generate_circle_{}.png".format(i), -1))
         frames.append(cv2.imread("test_2_frame_{}.png".format(i), 1))
         expected.append(cv2.imread("test_2_animated_image_{}.png".format(i), -1))
     
     obj = ip.ImageProcessing()
     
     obj.filename = "test_2"
     
     obj.gif_divorce = MagicMock(return_value=frames)
     obj.generate_circle = MagicMock(side_effect=generated_frames)
     
     results = obj.animated_image()
     
     for i in self.frame_count:
         with self.subTest(i=i):
             boolean = np.all(results[i] == expected[i])
             
             if not boolean:
                 self.assertTrue(boolean)
                 
     self.assertTrue(boolean)
Beispiel #2
0
 def test_generate_circle(self):
     frames = [None]*6
     desired = [None]*6
     
     
     for i in self.frame_count:
         desired[i] = cv2.imread("test_2_generate_circle_{}.png".format(i), -1)
         
     obj = ip.ImageProcessing()
     
     for i in self.frame_count:
         with self.subTest(i=i):
             
             image = cv2.imread("test_2_crop_circle_{}.png".format(i), 1)
             obj.crop_circle = MagicMock(return_value=image)
             
             image = cv2.imread("test_2_add_alpha_{}.png".format(i), -1)
             obj.add_alpha = MagicMock(return_value=image)
     
             frame = obj.generate_circle(frames)
     
            
    
             boolean = np.all(frame == desired[i])
             
             if not boolean:
                 self.assertTrue(boolean)
      
     
     self.assertTrue(boolean)
Beispiel #3
0
def test():
    img = cv2.imread("./img/153g.bmp", 0)
    ip = ImageProcessing.ImageProcessing(img)
    ip.doHoughTrans()
    img = ip.cannyImg[ip.C - 125:ip.C + 125, :]

    waveHeight, waveLenght = dp.getWaveParaByPeak(img)
Beispiel #4
0
 def test_get_frames(self):
     gif = Image.open("test_2")
     frames = []
     
     obj = ip.ImageProcessing()
     
     try:
         i = 0
         while True:
             gif.seek(i)
             imgframe = gif.copy()
             
             if i == 0:
                 palette = imgframe.getpalette()
                 
             else:
                 imgframe.putpalette(palette)
                 
             frames.append(imgframe)
             
             i += 1
             
     except EOFError:
         pass
 
     for i in self.frame_count:
         frames[i] = obj.get_frames(frames[i])
      
     for i in self.frame_count:
         comparable = cv2.imread("test_2_frame_{}.png".format(i), 1)
         
         if np.all(comparable != frames[i]):
             self.assertTrue(False)
             
     self.assertTrue(True)
Beispiel #5
0
	def __init__(self):
		self.imageProcessing = ImageProcessing.ImageProcessing()
		self.robotMovement = RobotMovement.RobotMovement()
		self.Sensors = Sensors.Sensors()
		self.wiiRemote = WiiRemote.WiiRemote()
		self.running = True
		self.mainloop()
Beispiel #6
0
 def test_get_size(self):
     image = cv2.imread("test_1", 1)
     
     obj = ip.ImageProcessing()
     
     dimensions = obj.get_size(image)
     
     self.assertEqual(dimensions, (480, 640))
Beispiel #7
0
 def onClickedBtnFocus(self):
     self.ci.setRoiToDefault()
     self.ci.getOneFrame()
     self.ci.endCapture()
     ip = ImageProcessing.ImageProcessing(self.ci.img)
     ip.doHoughTrans()
     self.ci.setRoi(self.ROIRANGE, ip.C - self.ROIRANGE/2)
     self.ci.startCapture()
Beispiel #8
0
 def test_add_alpha(self):
     input_image = cv2.imread("test_1_crop_circle_0.png", 1)
     result_image = cv2.imread("test_1_add_alpha_0.png", -1)
     
     obj = ip.ImageProcessing()
     
     result = obj.add_alpha(input_image)
     
     boolean = np.all(result == result_image)
     
     self.assertTrue(boolean)
Beispiel #9
0
 def test_get_size(self):
     obj = ip.ImageProcessing()
     
     for i in self.frame_count:
         with self.subTest(i=i):
             
             image = cv2.imread("test_2_frame_{}.png".format(i), 1)       
    
             dimensions = obj.get_size(image)
     
             self.assertEqual(dimensions, (212, 314))
    def test_nonanimated_image(self):
        filename = "test_1"

        obj = ip.ImageProcessing()
        result = obj.image_processing(filename)

        comparable = cv2.imread("test_1_unanimated_image_0.png", -1)

        state = np.all(comparable == result[0])

        self.assertTrue(state)
Beispiel #11
0
 def test_trim_square(self):
     input_image = cv2.imread("test_1_pre_trim_square_0.png", 1)
     result_image = cv2.imread("test_1_trim_square_0.png", 1)
     
     obj = ip.ImageProcessing()
     
     center = 240, 320
     result = obj.trim_square(input_image, center, 240)
     
     boolean = np.all(result == result_image)
     
     self.assertTrue(boolean) 
Beispiel #12
0
 def test_find_min(self):
     x = [212, 314, 0, -1]
     y = [314, 212, 0, -2]
     result = [0, 1, 1, 1]
     
     obj = ip.ImageProcessing()
     
     for i in range(len(result)):
         if obj.find_min(x[i], y[i]) != result[i]:
             self.assertTrue(False)
             
     self.assertTrue(True)  
Beispiel #13
0
    def initCamera(self):
        self.ci = Camera.CameraInterface()  # 获取界面中的相机接口
        self.ci.openCamera()
        self.ci.setAttribute()
        firstFrame = self.ci.getFirstFrame()
        ip = ImageProcessing.ImageProcessing(firstFrame)
        if ip.doHoughTrans():
            self.HOUGH_LINE_Y = ip.C
        else:
            self.HOUGH_LINE_Y = self.IMG_HEIGHT/2

        self.ci.setRoi(self.ROIRANGE, ip.C-self.ROIRANGE/2)
        self.ci.startCapture()
Beispiel #14
0
 def test_image_processing(self):
     result_image = cv2.imread("test_1_image_processing_0.png", -1)
     
     obj = ip.ImageProcessing()
     
     unanimated_image_result = cv2.imread("test_1_generate_circle_0.png", -1)
     obj.generate_circle = MagicMock(return_value=unanimated_image_result)
     
     result = obj.image_processing("test_1")
     
     boolean = np.all(result == result_image)
     
     self.assertTrue(boolean)
Beispiel #15
0
 def test_add_alpha(self):
     for i in self.frame_count:
         with self.subTest(i=i):
             input_image = cv2.imread("test_2_crop_circle_{}.png".format(i), 1)
             result_image = cv2.imread("test_2_add_alpha_{}.png".format(i), -1)
     
             obj = ip.ImageProcessing()
     
             result = obj.add_alpha(input_image)
     
             boolean = np.all(result == result_image)
     
             self.assertTrue(boolean)
    def test_animated_image(self):
        filename = "test_2"

        obj = ip.ImageProcessing()
        result = obj.image_processing(filename)

        for i, res in enumerate(result):
            with self.subTest(i=i):
                comparable = cv2.imread(
                    "test_2_animated_image_{}.png".format(i), -1)

                state = np.all(comparable == res)

                self.assertTrue(state)
def main():
    classifier = ClassifyImage(
        'centernet_resnet50_v1_fpn_512x512_coco17_tpu-8/saved_model',
        'mscoco_label_map.pbtxt')
    camera = ImageProcessing(960, 720)
    while True:
        coords = classifier.find_person(camera.frameToNumpy())
        #print(coords)
        if not coords is False:
            print(coords)
        else:
            print("nothing")
        time.sleep(2)
    self.camera.release()
Beispiel #18
0
 def test_trim_square(self):
     for i in self.frame_count:
         with self.subTest(i=i):
             input_image = cv2.imread("test_2_pre_trim_square_{}.png".format(i), 1)
             result_image = cv2.imread("test_2_trim_square_{}.png".format(i), 1)
             
             obj = ip.ImageProcessing()
             
             center = 106, 157
             result = obj.trim_square(input_image, center, 106)
             
             boolean = np.all(result == result_image)
             
             self.assertTrue(boolean) 
Beispiel #19
0
 def test_image_processing(self):
     for i in self.frame_count:
         with self.subTest(i=i):
             result_image = cv2.imread("test_2_image_processing_{}.png".format(i), -1)
             
             obj = ip.ImageProcessing()
             
             unanimated_image_result = cv2.imread("test_2_generate_circle_{}.png".format(i), -1)
             obj.generate_circle = MagicMock(return_value=unanimated_image_result)
             
             result = obj.image_processing("test_2")
             
             boolean = np.all(result == result_image)
             
             self.assertTrue(boolean)
Beispiel #20
0
    def displayEdgeImg(self, oriImg):  # 边缘显示区域的处理
        if self.isMeasuring == 0:  # 打开系统,但是未选择测量时
            # 边缘显示区域也显示原始图像
            img = q2n.gray2qimage(oriImg)
            img = img.scaled(self.IMG_WIDTH/2, self.ROIRANGE/2, Qt.KeepAspectRatio)
            self.label_canny.setPixmap(QPixmap.fromImage(img))  # 在原始图像显示区域写入图像
            return

        elif self.isMeasuring == 2:  # 仅仅用于演示和显示边缘图像,不对图像进行运算处理
            ip = ImageProcessing.ImageProcessing(oriImg)
            img = cv2.resize(ip.cannyImg, (self.IMG_WIDTH / 2, self.ROIRANGE / 2), cv2.INTER_NEAREST)
            img = q2n.gray2qimage(img)  # 此方法显示会将边缘放大,但实际处理的数据不会改变
            self.label_canny.setPixmap(QPixmap.fromImage(img))  # 在边缘显示区域写入图像
            return

        '''单击【自动测量按钮后】 self.isMeasuring==1的情况'''
        ip = ImageProcessing.ImageProcessing(oriImg)
        topCurve, bottomCurve = dp.getEdgeList(ip.cannyImg)
        # waveHeightByPeak, waveLengthByPeak = dp.getWaveParaByPeak(topCurve, bottomCurve)
        waveHeightBySin, waveLengthBySin = dp.getWaveParaBySin(topCurve, bottomCurve)

        # 显示钢丝波高的值
        waveShow = "%0.1f" % (waveHeightBySin * 6.6188 - 7.356)
        waveShow += "um"
        self.label_wave_height.setText(QString(str(waveShow)))
        img = cv2.resize(ip.cannyImg, (self.IMG_WIDTH / 2, self.ROIRANGE / 2), cv2.INTER_NEAREST)
        img = q2n.gray2qimage(img)  # 此方法显示会将边缘放大,但实际处理的数据不会改变
        self.label_canny.setPixmap(QPixmap.fromImage(img))  # 在边缘显示区域写入图像

        self.cntImgMeasuring += 1
        self.progressBar.setValue(self.cntImgMeasuring)  # 更新进度条当前进度
        self.waveHeightList.append(waveHeightBySin)
        self.waveLengthList.append(waveLengthBySin)  # 计数器和数据记录

        if self.cntImgMeasuring > self.rotatePeriod:  # 测量时间大于设定值
            self.completeMeasure()  # 测量完成进行相应得清零和整理工作
Beispiel #21
0
 def start(self, getter):
     self.keyboard_input = getter
     self.picture_to_show = self.keyboard_input.get()
     self.picture_storage = PictureStorage()
     self.settings = Settings.Settings()
     self.camera = Camera()
     self.tools = ImageProcessing.ImageProcessing(self.picture_storage, self.settings)
     self.window = Window(self.settings, "Bilder")
     self.main_window = Window(self.settings, "Taschenrechner")
     self.calculator = Calculator.Calculator()
     self.gui = GUI.GUI(self.picture_storage, self.settings)
     self.history = History()
     self.stage = 0
     self.buttons = ButtonGenerator(self.picture_storage)
     self.delete_history = History()
     self._run()
Beispiel #22
0
 def test_crop_circle(self):
     input_image = cv2.imread("test_1", 1)
     result_image = cv2.imread("test_1_crop_circle_0.png", 1)
     trim_square_result = cv2.imread("test_1_trim_square_0.png", 1)
     
 
     obj = ip.ImageProcessing()
     
     obj.get_size = MagicMock(return_value=(480, 640))
     obj.find_min = MagicMock(return_value=0)
     obj.trim_square = MagicMock(return_value=trim_square_result)
     
     result = obj.crop_circle(input_image)
     
     boolean = np.all(result == result_image)
     
     self.assertTrue(boolean)  
Beispiel #23
0
def main():
    ci = Camera.CameraInterface()
    ci.openCamera()
    ci.setAttribute(mode="Continuous")
    img = ci.getFirstFrame()
    ip = ImageProcessing.ImageProcessing(img)
    ip.doHoughTrans()
    print "ip.C:", ip.C

    ci.setRoi(250, ip.C - 125)
    ci.startCapture()
    while True:
        ci.getOneFrame()
        cv2.imshow("test", ci.img)
        k = cv2.waitKey(1)
        if k == 0x1b:
            cv2.destroyAllWindows()
            break
Beispiel #24
0
 def test_gif_divorce(self):
     gif = Image.open("test_2")
     frames = []
     obj = ip.ImageProcessing()
     
     
     frames = obj.gif_divorce(gif)
     
     for i in self.frame_count:
         with self.subTest(i=i):
             comparable = cv2.imread("test_2_frame_{}.png".format(i), 1)
             
             boolean = np.all(comparable == frames[i])
             
             if not boolean:
                 self.assertTrue(boolean)
                 
     self.assertTrue(boolean)
Beispiel #25
0
    def __init__(self, settings, connection, cropscoordinates, history):
        self.settings = settings
        self.connection = connection
        self.cropscoordinates = cropscoordinates
        self.history = history

        self.imageprocessing = ImageProcessing.ImageProcessing(settings)
        self.pool = ThreadPool()

        self.local = not (self.settings.client_server)
        if self.local:
            if self.settings.verbosity >= 2:
                print("Evaluation init, local model of Darkflow")
            self.local_model = self.init_local()

        if self.settings.precompute_attention_evaluation:
            # initialize hashmaps / dictionaries
            self.precomputations_started = {}  # <frame_number> => thread id
            self.precomputations_finished = {}  # <frame_number> => results
Beispiel #26
0
 def test_crop_circle(self):
     for i in self.frame_count:
         with self.subTest(i=i):
             input_image = cv2.imread("test_2_frame_{}.png".format(i), 1)
             result_image = cv2.imread("test_2_crop_circle_{}.png".format(i), 1)
             trim_square_result = cv2.imread("test_2_trim_square_{}.png".format(i), 1)
             
         
             obj = ip.ImageProcessing()
             
             obj.get_size = MagicMock(return_value=(212, 314))
             obj.find_min = MagicMock(return_value=0)
             obj.trim_square = MagicMock(return_value=trim_square_result)
             
             result = obj.crop_circle(input_image)
             
             boolean = np.all(result == result_image)
             
             self.assertTrue(boolean)  
Beispiel #27
0
 def test_generate_circle(self):
     input_image = cv2.imread("test_1", 1)
     
     image = []
     image.append(input_image)
     
     result_image = cv2.imread("test_1_generate_circle_0.png", -1)
     
     obj = ip.ImageProcessing()
     
     crop_circle_result = cv2.imread("test_1_crop_circle_0.png", 1)
     obj.crop_circle = MagicMock(return_value=crop_circle_result)
     
     add_alpha_result = cv2.imread("test_1_add_alpha_0.png", -1)
     obj.add_alpha = MagicMock(return_value=add_alpha_result)
     
     result = obj.generate_circle(image)
     
     boolean = np.all(result == result_image)
     
     self.assertTrue(boolean) 
Beispiel #28
0
def main():
    img = cv2.imread("./img/noise2.bmp", 0)
    ip = ImageProcessing.ImageProcessing(img)
    ip.doHoughTrans()
    img = ip.cannyImg[ip.C - 125:ip.C + 125, :]
    topCurve, bottomCurve = dp.imgToList(img)

    maxTabTopCurve, minTabTopCurve = dp.peakdet(topCurve,
                                                0.5)  # 通过函数直接找到极值点,包含了一些噪点。
    maxTabBottomCurve, minTabBottomCurve = dp.peakdet(bottomCurve, 0.5)

    peakTopCurve = dp.getWavePeak(maxTabTopCurve, line="TopCurve")
    peakBottomCurve = dp.getWavePeak(minTabBottomCurve, line="BottomCurve")

    waveHeight, waveLength = dp.peakPointToWavePara(peakTopCurve,
                                                    peakBottomCurve)

    plt.scatter(range(len(topCurve)), topCurve, c="r", s=1)
    plt.scatter(range(len(bottomCurve)), bottomCurve, c="g", s=2)
    plt.plot(range(2048), [peakTopCurve.mean(axis=0)[1]] * 2048)
    plt.plot(range(2048), [peakBottomCurve.mean(axis=0)[1]] * 2048)
    for i in range(peakTopCurve.shape[0]):
        x = [peakTopCurve[i, 0]] * 2
        y = [
            peakTopCurve.mean(axis=0)[1] + 5,
            peakTopCurve.mean(axis=0)[1] - 5
        ]
        plt.plot(x, y)
    for i in range(peakBottomCurve.shape[0]):
        x = [peakBottomCurve[i, 0]] * 2
        y = [
            peakBottomCurve.mean(axis=0)[1] + 5,
            peakBottomCurve.mean(axis=0)[1] - 5
        ]
        plt.plot(x, y)
    plt.show()
def extract_ines_of_text_from_image_and_match_label(imageArray, text,fontname, folderSave):
    lines_txt = text.split('\n')
    num_lines_txt = len(lines_txt)
    print(num_lines_txt)
    num_line=0
    newImagesForTrain = []

    width = imageArray.shape[1]
    height = imageArray.shape[0]
    boundries = ImageProcessing.GetLineBounds(imageArray)

    print(len(boundries))
    num_lines_image = len(boundries)
    for i in range(len(boundries)):
        x, y, w, h = boundries[i]
        cutImage = imageArray[max(0, min(y, y+h)-NUMPIXELS):min(max(y, y+h)+NUMPIXELS,height) , max(0, min(x, x+w)-NUMPIXELS) :min(width, max(x, x+w)+NUMPIXELS)]
        while lines_txt[num_line]=="" or lines_txt[num_line]==" " and num_line<num_lines_txt-1:
            num_line+=1
        if num_line<=num_lines_txt-1:
            Label = lines_txt[num_line]
            num_line += 1
            newImagesForTrain.append(ImageProcessing.ImageProcessing(cutImage, imagePath=None, handwrite_ID=fontname, Label = Label))

    Insert_to_folder(newImagesForTrain, folderSave)
Beispiel #30
0
    def begin(self):
        #print("Starting processing")
        imageProcessor = ImageProcessing(self.meeting, self.arrayStudents,
                                         self.size)
        confidenceMatrix = imageProcessor.processImageAndGetConfidenceMatrix()
        #print("done confidence:")
        #for i in range(len(confidenceMatrix)):
        #    print(confidenceMatrix[i])

        useDelete = True
        useSocial = True
        matcher = Matcher(self.meeting, self.arrayStudents)
        attendance = matcher.matchStudents(confidenceMatrix, useDelete,
                                           useSocial)
        output = Output(self.meeting, self.arrayStudents,
                        self.meeting.getCroppedFaces(), attendance)
        imageOrginalWithAttedance, imageAttendancePath = output.createAndWriteAttendacePiture(
            "Matching")

        #write the attedance picture to the db
        self.database.writeImageWithAttendance(
            self.db, imageOrginalWithAttedance,
            self.meeting.getMeetingDirectory(), imageAttendancePath)

        #write the attedance to the db
        self.database.writeAttendance(self.db, self.arrayStudents)

        #write the average social matrix to the db if its
        if (self.meeting.getFirstMeeting() == True):
            finalAverageSocialMatrix = output.findSocialMatrixFirstMeeting()
        else:
            finalAverageSocialMatrix = output.findAverageSocialMatrix()

        self.database.writeSocialMatrix(self.db, self.meeting,
                                        finalAverageSocialMatrix,
                                        self.arrayStudents)

        output.printAttendance()
        if (1 == 2):
            useDelete = False
            useSocial = True
            matcher = Matcher(self.meeting, self.arrayStudents)
            attendance = matcher.matchStudents(confidenceMatrix, useDelete,
                                               useSocial)
            output4 = Output(self.meeting, self.arrayStudents,
                             self.meeting.getCroppedFaces(), attendance)
            output4.createAndWriteAttendacePiture("SocialNoDelete")
            output4.printAttendance()

            useDelete = True
            useSocial = False
            matcher = Matcher(self.meeting, self.arrayStudents)
            attendance = matcher.matchStudents(confidenceMatrix, useDelete,
                                               useSocial)
            output3 = Output(self.meeting, self.arrayStudents,
                             self.meeting.getCroppedFaces(), attendance)
            output3.createAndWriteAttendacePiture("Social")
            output3.printAttendance()

            useDelete = False
            useSocial = False
            matcher = Matcher(self.meeting, self.arrayStudents)
            attendance = matcher.matchStudents(confidenceMatrix, useDelete,
                                               useSocial)
            output2 = Output(self.meeting, self.arrayStudents,
                             self.meeting.getCroppedFaces(), attendance)
            output2.createAndWriteAttendacePiture("MatchingNoDelete")
            output2.printAttendance()