python - 在服务器上执行 python 脚本
问题描述
我想在服务器上运行这个 python 脚本:
#!C:\Users\Username\Anaconda3\python.exe
import cgi
print("Content-type: text/html\n")
print("""<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Title</title>
</head>
<body>""")
import cv2
import os
cam = cv2.VideoCapture(0)
cam.set(3, 640) # set video width
cam.set(4, 480) # set video height
face_detector = cv2.CascadeClassifier('haarcascade_frontalface_alt_tree.xml')
# For each person, enter one numeric face id
face_id = 1
print("\n [INFO] Initializing face capture. Look the camera and wait ...")
# Initialize individual sampling face count
count = 0
while (True):
ret, img = cam.read()
# img = cv2.flip(img, -1) # flip video image vertically
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_detector.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
count += 1
# Save the captured image into the datasets folder
cv2.imwrite("dataset/User." + str(face_id) + '.' + str(count) + ".jpg", gray[y:y + h, x:x + w])
cv2.imshow('image', img)
k = cv2.waitKey(100) & 0xff # Press 'ESC' for exiting video
if k == 27:
break
elif count >= 30: # Take 30 face sample and stop video
break
# Do a bit of cleanup
print("\n [INFO] Exiting Program and cleanup stuff")
cam.release()
cv2.destroyAllWindows()
print("""</body>
</html>""")
页面呈现,但未cv2
导入库。导入库后,脚本结束。你怎么能解决这个问题?OpenCV 通过 Anaconda 安装。
解决方案
这是因为服务器上没有安装 cv2,如果您可以访问服务器的终端,请尝试以下操作:
pip install opencv-python
推荐阅读
- django - Django查询返回多个用户而不是一个
- r - 在 UTM 中定义平面点阵列的舍入参数
- bash - Asterisk 13 - system() 拨号计划应用程序无法在文件系统上调用 bash 脚本
- angular - Angular 2动态禁用FormControl
- sql - 将字符注入日期列
- facebook - 用于 Facebook Messenger 的 IBM watson 聊天机器人
- android - opencv在变量中获取fps
- jasmine - AfterEach 和 BeforeEach 仅适用于 describe()s
- node.js - 将来自 any() 的 PostgreSQL 响应解析为 JS 对象
- excel - Excel 公式返回最新日期旁边的值