def site_get(): document_path = Config.SAVE_DOCUMENT_PATH res = {} if request.method == 'POST': id = request.form["id"] try: with open(document_path + "site_" + id + ".txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) except Exception as e: print(e.__cause__) print('现在还没有存储该site') frame_location = Site(0, 0, 0, 0) tmp2 = frame_location.locate_y + frame_location.move_y tmp1 = frame_location.locate_x + frame_location.move_x res['site_left_top'] = str(frame_location.locate_x) + ',' + str( frame_location.locate_y) res['site_left_bottom'] = str( frame_location.locate_x) + ',' + str(tmp2) res['site_right_top'] = str(tmp1) + ',' + str(frame_location.locate_y) res['site_right_bottom'] = str(tmp1) + ',' + str(tmp2) # return redirect(url_for('main.index')) return res
def multi_ipc_video(): ips = [] path_in = './app/static/video/' path_out = '../static/video/' image_path = Config.UPLOAD_IMAGE_PATH document_path = Config.SAVE_DOCUMENT_PATH with open(document_path + "ipcConfig.txt", "r+") as f: a = f.readlines() for i in a: ips.append(i) try: with open(document_path + "site_0.txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) except Exception as e: frame_location = Site(0, 0, 0, 0) tmp2 = frame_location.locate_y + frame_location.move_y tmp1 = frame_location.locate_x + frame_location.move_x site_left_top = str(frame_location.locate_x) + ',' + str(frame_location.locate_y) site_left_bottom = str(frame_location.locate_x) + ',' + str(tmp2) site_right_top = str(tmp1) + ',' + str(frame_location.locate_y) site_right_bottom = str(tmp1) + ',' + str(tmp2) return render_template('multi_ipc_video.html', ips=ips, site_left_top=site_left_top, site_left_bottom=site_left_bottom, site_right_top=site_right_top, site_right_bottom=site_right_bottom, )
def multi_video(): video_names = [] path_in = './app/static/video/' path_out = '../static/video/' image_path = Config.UPLOAD_IMAGE_PATH document_path = Config.SAVE_DOCUMENT_PATH for dirpath, dirnames, filenames in os.walk(path_in): for filename in filenames: # dir_file_name = os.path.join(dirpath, filename) dir_file_name = filename if os.path.splitext(dir_file_name)[ 1] == '.mp4': # (('./app/static/movie', '.mp4')) print(dir_file_name) video_names.append(path_out + dir_file_name) with open(document_path + "site_0.txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) video_src = video_names[0] tmp2 = frame_location.locate_y + frame_location.move_y tmp1 = frame_location.locate_x + frame_location.move_x site_left_top = str(frame_location.locate_x) + ',' + str( frame_location.locate_y) site_left_bottom = str(frame_location.locate_x) + ',' + str(tmp2) site_right_top = str(tmp1) + ',' + str(frame_location.locate_y) site_right_bottom = str(tmp1) + ',' + str(tmp2) return render_template( "multi_video.html", video_names=video_names, site_left_top=site_left_top, site_left_bottom=site_left_bottom, site_right_top=site_right_top, site_right_bottom=site_right_bottom, )
def li_multiple_plot(length, file_location=''): plt.figure() plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号 plt.rcParams['figure.figsize'] = (8.0, 5.0) plt.rcParams['savefig.dpi'] = 200 # 图片像素 plt.rcParams['figure.dpi'] = 200 # 分辨率 document_path = Config.SAVE_DOCUMENT_PATH for i in range(length): csv_data = pd.read_csv(file_location + "sand_" + str(i) + ".csv", header=None, names=['x', 'y']) with open(document_path + "site_" + str(i) + ".txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) plt.plot(csv_data['x'], frame_location.locate_y + frame_location.move_y - csv_data['y'], label='video_' + str(i)) name = Config.UPLOAD_IMAGE_PATH + 'multiple_lines.png' plt.legend() plt.savefig(name) plt.close() return name
def picture(): # TODO 2019/10/1 12:02 liliangbin 当前帧解码 ,并调用图像处理函数 返回一个字符串 # 输入的base64编码字符串必须符合base64的padding规则。“当原数据长度不是3的整数倍时, 如果最后剩下两个输入数据,在编码结果后加1个“=”; # 如果最后剩下一个输入数据,编码结果后加2个“=”;如果没有剩下任何数据,就什么都不要加,这样才可以保证资料还原的正确性。” # image_path = Config.UPLOAD_IMAGE_PATH document_path = Config.SAVE_DOCUMENT_PATH if request.method == 'POST': str = request.form['current_frame'] id = request.form['id'] img_np = base64_to_png(str) cv2.imwrite(image_path + "current_" + id + ".png", img_np) res = {} sub = PictureSub() # 背景图 background = cv2.imread(image_path + "back_" + id + ".png") currentFrame = img_np q = sub.subtract_demo(background, currentFrame) s = sub.inverse(q) t = sub.iblack(s, 220) cv2.medianBlur(t, 3) cv2.GaussianBlur(t, (5, 5), 1) cv2.GaussianBlur(t, (15, 15), 0) cv2.bilateralFilter(t, 0, 100, 5) cv2.pyrMeanShiftFiltering(t, 10, 50) cv2.imwrite(image_path + "iblack_" + id + ".png", t) cv2.imwrite(image_path + "ipaint_" + id + ".png", s) with open(document_path + "site_" + id + ".txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) res = sub.ipaint(s, 50, id, frame_location.locate_x, frame_location.move_x, frame_location.locate_y, frame_location.move_y) res['max'] = frame_location.locate_y + frame_location.move_y # 变化得y轴 list_y = np.array(res['list_y']) data_total = res['max'] - list_y max_index = max(data_total.tolist()) res['list_y'] = data_total.tolist() res['max'] = max_index + 20 res['id'] = id # 以前使用的是jsonify===> 前端使用 data["list_y"]==>有什么区别 return res
def get_volume(): image_path = Config.UPLOAD_IMAGE_PATH document_path = Config.SAVE_DOCUMENT_PATH id = request.form['id'] s = cv2.imread(image_path + "iblack_" + id + ".png") sub = PictureSub() t = sub.iblack(s, 220) # cv2.imwrite(image_path + "iblack_" + id + ".png", t) with open(document_path + "site_" + id + ".txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) frame_area = areaRect.get_frame_area(frame_location.locate_x, frame_location.locate_y, frame_location.locate_x + frame_location.move_x, frame_location.locate_y + frame_location.move_y) # helen = Helen_formula() # # 沙子坐标 # points = [] # sand_coordinate = csv.reader(open('sand.csv', 'r')) # # 单路正向 # # 回路 # temp = 352 - (frame_location.locate_y + frame_location.move_y) # print(temp) # print("info\n") # sum = 0 # for volume in sand_coordinate: # points.append(Point(int(volume[0]), int(volume[1]))) # sum = sum + 1 # # for tmp in range(sum, 0, -1): # points.append(Point(points[tmp - 1].x, temp)) # sand_area = helen.get_area_of_poly_gon(points) sand_area = 0 # img = cv2.imread(image_path + "iblack_" + id + ".png") img=t sand_area = ostu(img) sand_frame_scale = float(sand_area) / float(frame_area) print(sand_frame_scale) print("sand_frame_scale") return { "frame_area": frame_area, "sand_area": sand_area, "sand_frame_scale": sand_frame_scale, "id": id }
def camera(): # TODO 2019/10/1 12:02 liliangbin 当前帧解码 ,并调用图像处理函数 返回一个字符串 # 输入的base64编码字符串必须符合base64的padding规则。“当原数据长度不是3的整数倍时, 如果最后剩下两个输入数据,在编码结果后加1个“=”; # 如果最后剩下一个输入数据,编码结果后加2个“=”;如果没有剩下任何数据,就什么都不要加,这样才可以保证资料还原的正确性。” # image_path = Config.UPLOAD_IMAGE_PATH document_path = Config.SAVE_DOCUMENT_PATH if request.method == 'POST': str = request.form['current_frame'] id = request.form['id'] with open(document_path + "site_" + '0' + ".txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) res = {} llistx = [] llisty = [] with open(document_path + 'sand_2.csv', 'r') as f: reader = csv.reader(f) for i in reader: llistx.append(i[0]) llisty.append(i[1]) res['list_x'] = llistx res['list_y'] = llisty res['max'] = frame_location.locate_y + frame_location.move_y # 变化得y轴 list_y = np.array(res['list_y']).astype(np.int) data_total = res['max'] - list_y max_index = max(data_total.tolist()) res['list_y'] = data_total.tolist() res['max'] = max_index + 20 res['id'] = id # 以前使用的是jsonify===> 前端使用 data["list_y"]==>有什么区别 return res
def get_multiple_iback(length): image_locatoion = Config.UPLOAD_IMAGE_PATH document_location = Config.SAVE_DOCUMENT_PATH results = [] for id in range(length): with open(document_location + "site_" + str(id) + ".txt", "r+") as f: a = f.readlines() frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) image_info = cv.imread(image_locatoion + 'iblack_' + str(id) + '.png') result_h = divideH(image_info, frame_location.locate_x, frame_location.locate_y, frame_location.move_x, frame_location.move_y) result_a = ostu(image_info, frame_location.locate_x, frame_location.locate_y, frame_location.move_x, frame_location.move_y) results.append( { "area": result_a, "height": result_h } ) return results
def change_datas(): # 输入的base64编码字符串必须符合base64的padding规则。“当原数据长度不是3的整数倍时, 如果最后剩下两个输入数据,在编码结果后加1个“=”; # 如果最后剩下一个输入数据,编码结果后加2个“=”;如果没有剩下任何数据,就什么都不要加,这样才可以保证资料还原的正确性。” s = [] image_path = Config.UPLOAD_IMAGE_PATH document_path = Config.SAVE_DOCUMENT_PATH if request.method == 'POST': new = eval(request.form.getlist("current_frame")[0]) id = request.form['id'] print(type(new), new) # new=[int(new[0]),int(new[1])] with open(document_path + "site_" + id + ".txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) with open(document_path + "sand_" + id + ".csv", "r+", encoding="utf-8", newline="") as f: reader = csv.reader(f) # writer = csv.writer(f) print("正在修改csv文件") for i in reader: s.append(i) for i in s: # print(i) if str(new[0]) == i[0]: s[s.index(i)][1] = str(frame_location.move_y + frame_location.locate_y - new[1]) break with open(document_path + "sand_" + id + ".csv", "w", newline="") as f: writer = csv.writer(f) for i in s: writer.writerow(i) print("csv文件修改成功") return "true"
def index(): # 这里的主入口是我们函数的dir 最好用绝对路径,临时用相对路径 # 使用url_for的时候使用的是函数名(路由名和函数名应一样。) video_names = [] path_in = './app/static/video/' path_out = '../static/video/' image_path = Config.UPLOAD_IMAGE_PATH document_path = Config.SAVE_DOCUMENT_PATH for dirpath, dirnames, filenames in os.walk(path_in): for filename in filenames: # dir_file_name = os.path.join(dirpath, filename) dir_file_name = filename if os.path.splitext(dir_file_name)[ 1] == '.mp4' or '.avi': # (('./app/static/movie', '.mp4')) print(dir_file_name) video_names.append(path_out + dir_file_name) with open(document_path + "site_0.txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) video_src = video_names[0] tmp2 = frame_location.locate_y + frame_location.move_y tmp1 = frame_location.locate_x + frame_location.move_x site_left_top = str(frame_location.locate_x) + ',' + str( frame_location.locate_y) site_left_bottom = str(frame_location.locate_x) + ',' + str(tmp2) site_right_top = str(tmp1) + ',' + str(frame_location.locate_y) site_right_bottom = str(tmp1) + ',' + str(tmp2) return render_template( 'index.html', video_names=video_names, site_left_top=site_left_top, site_left_bottom=site_left_bottom, site_right_top=site_right_top, site_right_bottom=site_right_bottom, video_src=video_src, )
def picture(): # TODO 2019/10/1 12:02 liliangbin 当前帧解码 ,并调用图像处理函数 返回一个字符串 # 输入的base64编码字符串必须符合base64的padding规则。“当原数据长度不是3的整数倍时, 如果最后剩下两个输入数据,在编码结果后加1个“=”; # 如果最后剩下一个输入数据,编码结果后加2个“=”;如果没有剩下任何数据,就什么都不要加,这样才可以保证资料还原的正确性。” # import time start = time.clock() # 中间写上代码块 image_path = Config.UPLOAD_IMAGE_PATH document_path = Config.SAVE_DOCUMENT_PATH if request.method == 'POST': str = request.form['current_frame'] id = request.form['id'] imageStart = time.clock() img_np = base64_to_png(str) cv2.imwrite(image_path + "current_" + id + ".png", img_np) imageEnd = time.clock() print('base64topng: %s Seconds' % (imageEnd - imageStart)) res = {} sub = PictureSub() # 背景图 writeImgeStart = time.clock() background = cv2.imread(image_path + "back_" + id + ".png") print(background.shape) writeImgeEnd = time.clock() print('WriteImge: %s Seconds' % (writeImgeEnd - writeImgeStart)) currentFrame = img_np print(currentFrame.shape) q = sub.subtract_demo(background, currentFrame) substractIMRun = time.clock() print('substract : %s Seconds' % (substractIMRun - writeImgeEnd)) s = sub.inverse(q) InvserseSTOP = time.clock() print('inverse : %s Seconds' % (InvserseSTOP - substractIMRun)) # t = sub.iblack(s, 220) imageRun = time.clock() print('iblack: %s Seconds' % (imageRun - InvserseSTOP)) print('sub starct ALL : %s Seconds' % (imageRun - writeImgeEnd)) # cv2.imwrite(image_path + "iblack_" + id + ".png", t) cv2.imwrite(image_path + "ipaint_" + id + ".png", s) imageStop = time.clock() print('write twoImge: %s Seconds' % (imageStop - imageRun)) with open(document_path + "site_" + id + ".txt", "r+") as f: a = f.readlines() print(a) frame_location = Site(int(a[0]), int(a[1]), int(a[2]), int(a[3])) res = sub.ipaint(s, 220, id, frame_location.locate_x, frame_location.move_x, frame_location.locate_y, frame_location.move_y) res['max'] = frame_location.locate_y + frame_location.move_y # 变化得y轴 list_y = np.array(res['list_y']) data_total = res['max'] - list_y max_index = max(data_total.tolist()) res['list_y'] = data_total.tolist() res['max'] = max_index + 20 res['id'] = id # 以前使用的是jsonify===> 前端使用 data["list_y"]==>有什么区别 end = time.clock() print('Running time: %s Seconds' % (end - start)) return res