def sending(request): #웹캠 전달 받은 것 처리 if request.method == 'POST': #경로설정 current_path = os.path.dirname( os.path.abspath( __file__ ) ) code_path = os.path.abspath(os.path.join(current_path, 'code')) videoModule_path = os.path.abspath(os.path.join(code_path, 'VideoModule')) sys.path.append(videoModule_path) # 폴더 하나 써서 추가하기: webcams current_url = request.POST.get('url') video = int(current_url.split('/')[-3])#seed1 last_row = WebCam.objects.order_by('id').last()#### last_row_id = 0 if last_row is None: last_row_id = 0 else: last_row_id = last_row.id file_path =str(video) +'_' + str(last_row_id+1) +'.mp4' save_path = os.path.abspath(os.path.join(current_path, os.pardir)) save_path = os.path.abspath(os.path.join(save_path, 'media')) save_path = os.path.abspath(os.path.join(save_path, file_path)) with open(save_path, 'wb') as f:##경로 지정 하고, 이름 유니크하게 바꿔야. f.write(request.FILES['video'].read()) #분석 및 저장 use_i_th_frame = 9 #30==1sec from Commander import Commander import cv2 from PIL import Image import numpy as np commander = Commander() dumped, capture = commander.for_web_cam(use_i_th_frame, save_path) capture_path =str(video) +'_' + str(last_row_id+1) +'.png' capture_save_path = os.path.abspath(os.path.join(current_path, os.pardir)) capture_save_path = os.path.abspath(os.path.join(capture_save_path, 'media')) capture_save_path = os.path.abspath(os.path.join(capture_save_path, capture_path)) #print(capture_save_path) if len(dumped) != 0: destRGB = cv2.cvtColor(capture, cv2.COLOR_BGR2RGB) captured_img = Image.fromarray(destRGB, 'RGB') captured_img.save(capture_save_path) will_inserted = WebCam(video_id=str(video), json_data=dumped, video_path=save_path, capture_path=capture_path) will_inserted.save() else: return HttpResponse("Something Wrong in file uploading") context = {} return HttpResponse(json.dumps(context), "application/json")