Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Upload 2 files
Browse files- demo.py +7 -7
- similarity_check.py +15 -32
    	
        demo.py
    CHANGED
    
    | @@ -61,7 +61,7 @@ def get_face_encoding(path): | |
| 61 | 
             
            #     if cv2.waitKey(1) & 0xFF == ord('q'):
         | 
| 62 | 
             
            #         break
         | 
| 63 |  | 
| 64 | 
            -
             | 
| 65 | 
             
            def process_frame(frame, process_this_frame, face_locations, faces, face_names, score):
         | 
| 66 |  | 
| 67 | 
             
                hkid_face_encoding = get_face_encoding("image")
         | 
| @@ -84,12 +84,12 @@ def process_frame(frame, process_this_frame, face_locations, faces, face_names, | |
| 84 | 
             
                    #     print(f'frame: {len(frame)}')
         | 
| 85 | 
             
                        # try: 
         | 
| 86 | 
             
                        #     small_frame = cv2.imread(image_dir)
         | 
| 87 | 
            -
                     | 
| 88 | 
             
                    # else:
         | 
| 89 | 
             
                    #     print('fram has nth')
         | 
| 90 |  | 
| 91 | 
             
                    # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
         | 
| 92 | 
            -
                    rgb_small_frame = cv2.cvtColor( | 
| 93 |  | 
| 94 | 
             
                    # Find all the faces and face encodings in the current frame of video
         | 
| 95 | 
             
                    face_locations = face_recognition.face_locations(rgb_small_frame)
         | 
| @@ -142,10 +142,10 @@ def process_frame(frame, process_this_frame, face_locations, faces, face_names, | |
| 142 |  | 
| 143 | 
             
                for (top, right, bottom, left), name in zip(face_locations, face_names):
         | 
| 144 | 
             
                    # Scale back up face locations since the frame we detected in was scaled to 1/4 size
         | 
| 145 | 
            -
                     | 
| 146 | 
            -
                     | 
| 147 | 
            -
                     | 
| 148 | 
            -
                     | 
| 149 |  | 
| 150 | 
             
                    # Draw a box around the face
         | 
| 151 | 
             
                    cv2.rectangle(frame, (left, top), (right, bottom), (65, 181, 41), 4)
         | 
|  | |
| 61 | 
             
            #     if cv2.waitKey(1) & 0xFF == ord('q'):
         | 
| 62 | 
             
            #         break
         | 
| 63 |  | 
| 64 | 
            +
            # frames are the snapshot of the video
         | 
| 65 | 
             
            def process_frame(frame, process_this_frame, face_locations, faces, face_names, score):
         | 
| 66 |  | 
| 67 | 
             
                hkid_face_encoding = get_face_encoding("image")
         | 
|  | |
| 84 | 
             
                    #     print(f'frame: {len(frame)}')
         | 
| 85 | 
             
                        # try: 
         | 
| 86 | 
             
                        #     small_frame = cv2.imread(image_dir)
         | 
| 87 | 
            +
                    small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
         | 
| 88 | 
             
                    # else:
         | 
| 89 | 
             
                    #     print('fram has nth')
         | 
| 90 |  | 
| 91 | 
             
                    # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
         | 
| 92 | 
            +
                    rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
         | 
| 93 |  | 
| 94 | 
             
                    # Find all the faces and face encodings in the current frame of video
         | 
| 95 | 
             
                    face_locations = face_recognition.face_locations(rgb_small_frame)
         | 
|  | |
| 142 |  | 
| 143 | 
             
                for (top, right, bottom, left), name in zip(face_locations, face_names):
         | 
| 144 | 
             
                    # Scale back up face locations since the frame we detected in was scaled to 1/4 size
         | 
| 145 | 
            +
                    top *= 4
         | 
| 146 | 
            +
                    right *= 4
         | 
| 147 | 
            +
                    bottom *= 4
         | 
| 148 | 
            +
                    left *= 4
         | 
| 149 |  | 
| 150 | 
             
                    # Draw a box around the face
         | 
| 151 | 
             
                    cv2.rectangle(frame, (left, top), (right, bottom), (65, 181, 41), 4)
         | 
    	
        similarity_check.py
    CHANGED
    
    | @@ -1,10 +1,10 @@ | |
| 1 | 
            -
            from  | 
| 2 | 
            -
            from model2 import model2
         | 
| 3 | 
             
            import checkTool as ct
         | 
| 4 | 
             
            import extract_pdf as pf
         | 
| 5 | 
             
            import extraction_data as ed
         | 
| 6 | 
             
            import get_chinese_name as cn
         | 
| 7 | 
             
            import search_engine as se
         | 
|  | |
| 8 |  | 
| 9 | 
             
            # get info from hkid card
         | 
| 10 |  | 
| @@ -43,29 +43,19 @@ def get_data(img1_path, img2_path): | |
| 43 |  | 
| 44 | 
             
                # img_fp = 'IMG_4495.jpg'
         | 
| 45 |  | 
| 46 | 
            -
                info1 = model1(img1_path)
         | 
| 47 | 
            -
                info2 = model2(img1_path)
         | 
| 48 |  | 
| 49 | 
            -
                def print_info(name, valid_hkid, hkid, issuedate):
         | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 |  | 
| 54 | 
            -
                cinfo = ct.combine_info(info1, info2)
         | 
|  | |
|  | |
| 55 |  | 
| 56 | 
             
                # get info from bank
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                # images = r'hangseng_page-0001.jpg'
         | 
| 59 | 
            -
                # bank_list = ['bankofchina','hangsengbank','hsbc','sc']
         | 
| 60 | 
            -
                # image_path = 'hangseng_page-0001.jpg'
         | 
| 61 | 
            -
                # post_url = r''
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                # name = pf.get_info_from_bank(img2_path)
         | 
| 64 | 
            -
                # name = pf.check_mr(name)
         | 
| 65 | 
            -
                # name = name.replace(' ', '')
         | 
| 66 | 
            -
                # name = name.lower()
         | 
| 67 | 
            -
             | 
| 68 | 
            -
                # data = pf.get_info_from_bank(img2_path, file_name)
         | 
| 69 | 
             
                data = ed.get_info_from_bank(img2_path)
         | 
| 70 | 
             
                name = data["nameStatement"]
         | 
| 71 |  | 
| @@ -75,24 +65,17 @@ def get_data(img1_path, img2_path): | |
| 75 | 
             
                # img_fp = 'IMG_1234.jpg'
         | 
| 76 | 
             
                name1 = cinfo[0]
         | 
| 77 | 
             
                threshold = 85
         | 
| 78 | 
            -
                # print(f'Name in HKID: {name1}')
         | 
| 79 | 
            -
                # print(f'Nmae in bank statement: {name}')
         | 
| 80 | 
             
                similarity_score = string_similarity(name,name1)
         | 
| 81 | 
            -
                # print(f'Similarity: {similarity_score}')
         | 
| 82 | 
            -
                # if (similarity_score >= threshold): # Above threshold
         | 
| 83 | 
            -
                #     print('It is the same person')
         | 
| 84 | 
            -
                # else: # Below threshold
         | 
| 85 | 
            -
                #     print('It is not the same person')
         | 
| 86 | 
             
                data["similarity_score"] = similarity_score
         | 
| 87 | 
             
                data["name_on_id"] = name1
         | 
| 88 | 
             
                data["hkid"] = cinfo[2]
         | 
| 89 | 
             
                data["validity"] = cinfo[1]
         | 
| 90 | 
             
                data["issue_date"] = cinfo[3]
         | 
|  | |
| 91 |  | 
| 92 | 
            -
                #  | 
|  | |
| 93 | 
             
                # chi_name = cn.get_chiname(img1_path)["Chinese Name"]
         | 
| 94 | 
            -
                chi_name = "allen lau"
         | 
| 95 | 
             
                data["chi_name_id"] = chi_name
         | 
| 96 |  | 
| 97 | 
            -
                return data
         | 
| 98 | 
            -
                    
         | 
|  | |
| 1 | 
            +
            from model0 import model0
         | 
|  | |
| 2 | 
             
            import checkTool as ct
         | 
| 3 | 
             
            import extract_pdf as pf
         | 
| 4 | 
             
            import extraction_data as ed
         | 
| 5 | 
             
            import get_chinese_name as cn
         | 
| 6 | 
             
            import search_engine as se
         | 
| 7 | 
            +
            import get_chinese_code as cc
         | 
| 8 |  | 
| 9 | 
             
            # get info from hkid card
         | 
| 10 |  | 
|  | |
| 43 |  | 
| 44 | 
             
                # img_fp = 'IMG_4495.jpg'
         | 
| 45 |  | 
| 46 | 
            +
                # info1 = model1(img1_path)
         | 
| 47 | 
            +
                # info2 = model2(img1_path)
         | 
| 48 |  | 
| 49 | 
            +
                # def print_info(name, valid_hkid, hkid, issuedate):
         | 
| 50 | 
            +
                #     print(f'Name: {name}') # name is without space
         | 
| 51 | 
            +
                #     print(f'HKID: {hkid} and validity: {valid_hkid}')
         | 
| 52 | 
            +
                #     print(f'Date of issue: {issuedate}')
         | 
| 53 |  | 
| 54 | 
            +
                # cinfo = ct.combine_info(info1, info2)
         | 
| 55 | 
            +
                cinfo = model0(img1_path)
         | 
| 56 | 
            +
                print(cinfo)
         | 
| 57 |  | 
| 58 | 
             
                # get info from bank
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 59 | 
             
                data = ed.get_info_from_bank(img2_path)
         | 
| 60 | 
             
                name = data["nameStatement"]
         | 
| 61 |  | 
|  | |
| 65 | 
             
                # img_fp = 'IMG_1234.jpg'
         | 
| 66 | 
             
                name1 = cinfo[0]
         | 
| 67 | 
             
                threshold = 85
         | 
|  | |
|  | |
| 68 | 
             
                similarity_score = string_similarity(name,name1)
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 69 | 
             
                data["similarity_score"] = similarity_score
         | 
| 70 | 
             
                data["name_on_id"] = name1
         | 
| 71 | 
             
                data["hkid"] = cinfo[2]
         | 
| 72 | 
             
                data["validity"] = cinfo[1]
         | 
| 73 | 
             
                data["issue_date"] = cinfo[3]
         | 
| 74 | 
            +
                data["dateofbirth"] = cinfo[4]
         | 
| 75 |  | 
| 76 | 
            +
                # Get chinese name
         | 
| 77 | 
            +
                chi_name = cc.get_chinese_name(img1_path)
         | 
| 78 | 
             
                # chi_name = cn.get_chiname(img1_path)["Chinese Name"]
         | 
|  | |
| 79 | 
             
                data["chi_name_id"] = chi_name
         | 
| 80 |  | 
| 81 | 
            +
                return data
         | 
|  | 
