def cp(args): path = "/gaitlab/input/input.mp4" # remove the old file os.system('rm {}'.format(path)) # save the new file url = args["video_url"] with urllib.request.urlopen(url) as response, open(path, 'wb') as out_file: shutil.copyfileobj(response, out_file) # run predictions result, video = predict(path) files = {'file': video} # store results r = requests.post("http://www/annotation/{}/".format(args["annotation_id"]), files = files, data = {"result": json.dumps(result)}) return None
import requests import threading import csv import demo import img_process import time plt.rcParams.update({'figure.max_open_warning': 0}) #fix the memory error Chrome_driver_location = 'get_image/2/webdriver/chromedriver78' destination_url_student = 'https://irs.thsrc.com.tw/IMINT/?student=university' destination_url_default = 'https://irs.thsrc.com.tw/IMINT/' train_number = 434 #火車班次號碼 dir = '/Users/garys/Desktop/2.jpg' img_process.process(dir) #process passcode = demo.predict(dir) #predict print(passcode) driver = webdriver.Chrome(Chrome_driver_location) driver.get(destination_url_default) # 輸入範例網址,交給瀏覽器 cookie = driver.get_cookies() #get cookie pageSource = driver.page_source # 取得網頁原始碼 #driver.find_element_by_id("bookingMethod2").click() #driver.find_element_by_name("toTrainIDInputField").send_keys(train_number) driver.find_element_by_id('btn-confirm').click() 啟程站 = Select(driver.find_element_by_name('selectStartStation')) 啟程站.select_by_value("1") 終點站 = Select(driver.find_element_by_name('selectDestinationStation'))
def surveillance(): station = "None" cam1 = "../static/images/Camnormal.png" cam2 = "../static/images/Camnormal.png" cam3 = "../static/images/Camnormal.png" if session['stage'] == 0: target = os.path.join(APP_ROOT, 'static/videos') print(target) if not os.path.isdir(target): os.mkdir(target) session['filenames'] = [] for file in request.files.getlist("file"): print(file) session['filenames'].append(file.filename) destination = "/".join([target, file.filename]) print(destination) file.save(destination) text = urllib.parse.quote_plus("where is the nearest police station") url = 'https://google.com/search?q=' + text response = requests.get(url) soup = BeautifulSoup(response.text,'lxml') for g in soup.find_all(class_='kR1eme rllt__wrap-on-expand'): station = g.span.text break # model can be one of lstm, lrcn, mlp, conv_3d, c3d. model = 'lrcn' # Must be a weights file. saved_model = 'static/videos/lrcn-images.114-2.304.hdf5' # Sequence length must match the lengh used during training. seq_length = 40 # Limit must match that used during training. class_limit = None if model in ['conv_3d', 'c3d', 'lrcn']: data_type = 'images' image_shape = (80, 80, 3) elif model in ['lstm', 'mlp']: data_type = 'features' image_shape = None else: raise ValueError("Invalid model. See train.py for options.") if session['stage'] <3: prediction = predict(data_type, seq_length, saved_model, image_shape, os.path.splitext(session['filenames'][session['stage']])[0], class_limit) session['stage'] += 1 if session['stage'] == 1: session['prediction1'] = prediction if session['stage'] == 2: session['prediction2'] = prediction if session['stage'] == 3: session['prediction3'] = prediction if "Crime Detected" in prediction: if session['stage'] == 1: cam1 = "../static/images/camalert.gif" if session['stage'] == 2: cam2 = "../static/images/camalert.gif" if session['stage'] == 3: cam3 = "../static/images/camalert.gif" return render_template("surveillance.html", video0="../static/videos/" + session['filenames'][0], video1="../static/videos/" + session['filenames'][1], video2="../static/videos/" + session['filenames'][2], station=station, prediction1=session['prediction1'], prediction2=session['prediction2'], prediction3=session['prediction3'], stage = session['stage'], cam1=cam1, cam2=cam2, cam3=cam3)