def login(self, username, password): """ 模拟账号登陆,获取登陆cookie,得到属性session供之后的方法调用; 返回(code, msg) code=0正确, code=1发生错误 """ try: #get random check code r = self.session.get(login_url) checkcode = re.findall('var checkcode="(\d+)"', r.text)[0].encode('utf-8') #get img code number code_img_data = self.session.get(code_img_url, stream=True).raw.read() code = recognise(code_img_data).strip() data = { 'account':username, 'password':hashlib.md5(password).hexdigest(), 'code':code, 'checkcode':checkcode, 'Submit': '登 陆' } r = self.session.post(post_url, data=data) error_divs = etree.HTML(r.text).xpath('//div[@id="fielderror2"]') if not error_divs: self.is_login = True return (0, 'success') error_msg = etree.tostring(error_divs[0], method='text', encoding='utf-8') error_msg = re.findall(r" ([\s\S]*)</div>", error_msg)[0] return (1, error_msg) except: return False
def segmentImage(platel): resStr = '' plate = cv2.cvtColor(platel, cv2.COLOR_BGR2GRAY) plate = cv2.bilateralFilter(plate, 5, 15, 15) #21515 height = plate.shape[0] width = plate.shape[1] area = height * width #print(height,width) scale1 = 0.01 scale2 = 0.1 area_condition1 = area * scale1 area_condition2 = area * scale2 cv2.imshow(" Plate", plate) ret3, th3 = cv2.threshold(plate, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) try: contours, hierarchy = cv2.findContours(th3, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) #print(hierarchy) except Exception as e: print(e) contours = sorted(contours, key=cv2.boundingRect, reverse=False) cropped = [] results = [] i = 0 for cnt in contours: (x, y, w, h) = cv2.boundingRect(cnt) if (w * h > area_condition1 and w * h < area_condition2 and w / h > 0.3 and h / w > 0.3): cv2.drawContours(plate, [cnt], 0, (0, 255, 0), 1) cv2.rectangle(platel, (x, y), (x + w, y + h), (255, 0, 0), 1) c = th3[y:y + h, x:x + w] c = np.array(c) c = cv2.bitwise_not(c) #c = square(c) c = cv2.resize(c, (28, 28), interpolation=cv2.INTER_AREA) cv2.imshow("c", c) cv2.imshow(str(i), c) result = recognise(c) #print(c) cropped.append(c) if (result != None): results.append(result) i += 1 i = 0 cv2.imshow("done", platel) for i in results: resStr += str(i) #print(resStr) return resStr
def __validate_face(self, username): """This function is used to validate the user via face recognition. :param: (str) username of the customer """ face_rec = recognise() recognised_name = face_rec.start() if recognised_name == username: self.__successful_unlock(username) else: self.__print_to_console('Failed to Authenticate')
def __validate_face(self, username): """This function is used to validate the user via face recognition. :param: (str) username of the customer """ face_rec = recognise() recognised_name = face_rec.start() if recognised_name == username: if (self.__is_engineer): engineer_details = self.__socket_obj.load_engineer_details(self.__car_id) self.__successful_unlock_engineer(engineer_details) else: self.__successful_unlock(username) else: self.__print_to_console('Failed to Authenticate') self.quit()
""") os.system(f'aplay {third} >/dev/null 2>&1') mlcat("Verify the Speaker", """\ Now, we will insert the first three examples into the recognition system, and use these samples to verify the fourth audio by its unique voice characteristics. """) mlask(end="\n") # Play the fourth audio. mlcat("", """The fourth audio to be verified... """) os.system(f'aplay {fourth} >/dev/null 2>&1') recognise([first, second, third, fourth], False, key) print("") else: mlask(begin="\n", end="\n") mlcat("Speaker Recognition", f"""\ This service is currently (April 2021) only supported by the 'westus' region. Your current region is '{location}'. You can create an Azure Speech resource for 'westus' if you want to use this service and to utilise the RECOGNISE command. Once the appropriate resource has been created replace the key by running ml configure azspeech. """)
def test_isNotDetectingUntrainedFace(self): face_rec_2 = recognise() recognised_name = face_rec_2.start() self.assertEqual("uknown user", recognised_name)
def test_isDetectingTrainedFace(self): face_rec = recognise() recognised_name = face_rec.start() self.assertEqual("sainath", recognised_name)