gpt4 book ai didi

python - 在服务器上执行python脚本

转载 作者:行者123 更新时间:2023-12-02 17:56:39 24 4
gpt4 key购买 nike

我想在服务器上运行此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库未导入。导入库后,脚本结束。您该如何解决?通过Anaconda安装的OpenCV。

最佳答案

这是因为服务器上未安装cv2,如果您有权访问服务器的终端,请尝试以下操作:

pip install opencv-python

关于python - 在服务器上执行python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64535538/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com