diff --git a/IROCMdjango/IROCM/urls.py b/IROCMdjango/IROCM/urls.py index 4c1d51f..bf39426 100644 --- a/IROCMdjango/IROCM/urls.py +++ b/IROCMdjango/IROCM/urls.py @@ -22,4 +22,5 @@ urlpatterns = [ path('', views.index,name='index'), path('upload/', views.upload,name='upload'), path('results/', views.results,name='results'), + path('camera/', views.camera,name="camera"), ] \ No newline at end of file diff --git a/IROCMdjango/IROCM/views.py b/IROCMdjango/IROCM/views.py index 19a06a0..3394847 100644 --- a/IROCMdjango/IROCM/views.py +++ b/IROCMdjango/IROCM/views.py @@ -1,5 +1,7 @@ from django.shortcuts import render from django.views import View +from paddle.dataset.image import cv2 + from IROCMdjango import settings from flask import request @@ -49,7 +51,49 @@ def upload(request): print('其他请求') return render(request, 'upload.html', {}) - +def camera(request): + if request.method == 'POST': + print('正在使用摄像头') + print("=============================================") + print("= 热键(请在摄像头的窗口使用): =") + print("= x: 拍摄图片 =") + print("= q: 退出 =") + print("=============================================") + print() + #os.system('python E:\workspace\PyCharm\http1\IROCMdjango\IROCM\camera.py') + new_name = 'upimg.jpg' + class_name = os.path.join(settings.MEDIA_ROOT, new_name) + + # 摄像头 + cap = cv2.VideoCapture(0) + flag = 1 + num = 1 + # 检测是否在开启状态 + while (cap.isOpened()): + # 得到每帧图像 + ret_flag, Vshow = cap.read() + cv2.imshow("Capture_Test", Vshow) # 显示图像 + k = cv2.waitKey(1) & 0xFF # 按键判断 + if k == ord('s'): # 键盘按下s键即保存 + cv2.imwrite(class_name, Vshow) + print("success to save") + print("-------------------") + break + elif k == ord(' '): # 退出 + break + # 释放摄像头 + cap.release() + # 释放内存 + cv2.destroyAllWindows() + str = predict_image(class_name) + print(str) + lstr = predict_info(str) + print(lstr) + # 返回 + return render(request, 'results.html', {"data": str, "info": lstr}) + else: + print('其他请求') + return render(request, 'camera.html', {}) import paddle import numpy as np diff --git a/IROCMdjango/IROCMdjango/urls.py b/IROCMdjango/IROCMdjango/urls.py index 9043dd2..9541f44 100644 --- a/IROCMdjango/IROCMdjango/urls.py +++ b/IROCMdjango/IROCMdjango/urls.py @@ -23,6 +23,7 @@ from IROCM import views urlpatterns = [ path('',include('IROCM.urls')), path('upload/',views.upload,name="upload"), + path('camera/', views.camera, name="camera"), path('admin/', admin.site.urls), ] diff --git a/IROCMdjango/static/media/upimg.jpg b/IROCMdjango/static/media/upimg.jpg index eb4baa7..127a898 100644 Binary files a/IROCMdjango/static/media/upimg.jpg and b/IROCMdjango/static/media/upimg.jpg differ diff --git a/IROCMdjango/templates/IROCM/camera.html b/IROCMdjango/templates/IROCM/camera.html new file mode 100644 index 0000000..bef46c3 --- /dev/null +++ b/IROCMdjango/templates/IROCM/camera.html @@ -0,0 +1,112 @@ + +{% load staticfiles %} + +
+ +