def upload(i): path = '../new_pictures/' files1 = os.listdir(path) ntime = time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()) for step in files1: if step == "1.txt": continue split = os.path.splitext(step) pic_name = split[0] scaled_arr = [] img = cv2.imread(path + step) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) scaled = cv2.resize(gray, (160, 160), interpolation=cv2.INTER_LINEAR) scaled.astype(float) scaled = np.array(scaled).reshape(160, 160, 1) scaled = embeddings_pre.prewhiten(scaled) scaled_arr.append(scaled) feed_dict = { images_placeholder: scaled_arr, phase_train_placeholder: False, keep_probability_placeholder: 1.0 } #---------------------------------上傳資料庫--------------------------------- x = sess.run(embeddings, feed_dict=feed_dict) Data = { "user_name": pic_name + str(i), "embedding": str(x), "date": str(ntime) } conn = requests.post("http://140.136.150.100/upload.php", data=Data) #---------------------------------------------------------------------------- print(conn.text)
def save_image(self): var = self.ui.lineEdit.text() if self.check == 1: if var!='': #save_image前置,先儲存照片在本地 face = self.face face = cv2.cvtColor(face,cv2.COLOR_BGR2RGB) face = cv2.resize(face, (160, 160), interpolation=cv2.INTER_CUBIC) pic_path = "../new_pictures/"+var+".jpg" cv2.imwrite(pic_path,face) #跳出註冊提醒視窗 register_dialog = Register_Dialog(var,self.ui.setting_checkBox.isChecked(),self.good_setting,self.none_setting) #判斷是否第一次註冊 if self.ui.setting_checkBox.isChecked(): #確認是否拍了good跟none兩張照片 btn = register_dialog.buttonBox.button(QDialogButtonBox.Ok) if self.label_flag == 'good' and self.good_setting == 0: btn.setEnabled(True) elif self.label_flag == 'none' and self.none_setting==0: btn.setEnabled(True) else: btn.setEnabled(False) btn.setStyleSheet('''background-color: #A0A0A0; color: #C0C0C0''') result = register_dialog.exec_() if result == 1: if self.label_flag == 'good': self.good_setting = 1 if self.label_flag == 'none': self.none_setting = 1 #---------------照片上傳雲端-------------------- #Drive_upload(pic_path,var) #---------------------------------------------- #-----------重新執行特徵分析並上傳資料庫--------- path = '../new_pictures/' files1 = os.listdir(path) ntime = time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()) for step in files1: if step == "1.txt": continue split = os.path.splitext(step) pic_name = split[0] scaled_arr=[] img = cv2.imread(path + step) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) scaled =cv2.resize(gray,(160,160),interpolation=cv2.INTER_LINEAR) scaled.astype(float) scaled = np.array(scaled).reshape(160, 160, 1) scaled = embeddings_pre.prewhiten(scaled) scaled_arr.append(scaled) feed_dict = { images_placeholder: scaled_arr, phase_train_placeholder:False ,keep_probability_placeholder:1.0} #---------------------------------上傳資料庫--------------------------------- x = sess.run(embeddings, feed_dict=feed_dict) Data = { "user_name" : pic_name, "embedding" : str(x), "date" : str(ntime) } conn = requests.post("http://140.136.150.100/upload.php", data = Data) #---------------------------------------------------------------------------- print(conn.text) #---------------------------------------------- #跳出上傳完成視窗 dialog = Dialog_window() self.reload() var = self.ui.lineEdit.setText('') #用完就刪除照片 if os.path.exists(pic_path): os.remove(pic_path)