Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python OpenCV3在视频上写入文本_Python_Python 3.x_Raspbian_Raspberry Pi3_Opencv3.1 - Fatal编程技术网

Python OpenCV3在视频上写入文本

Python OpenCV3在视频上写入文本,python,python-3.x,raspbian,raspberry-pi3,opencv3.1,Python,Python 3.x,Raspbian,Raspberry Pi3,Opencv3.1,我有树莓皮3与树莓杰西安装。OpenCV3和python 3.0也已安装。我得到了一个检测人脸的python示例代码。我需要在屏幕上写一些文字,但不是写在上面。我需要写一次文本,而不是在每个面上重复。下面是代码 import cv2 import sys from tkinter import * from tkinter import messagebox faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_defaul

我有树莓皮3与树莓杰西安装。OpenCV3和python 3.0也已安装。我得到了一个检测人脸的python示例代码。我需要在屏幕上写一些文字,但不是写在上面。我需要写一次文本,而不是在每个面上重复。下面是代码

import cv2
import sys
from tkinter import *
from tkinter import messagebox

faceCascade =  cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

video_capture = cv2.VideoCapture(0)
video_capture.set(3,500)
video_capture.set(4,300)
video_capture.set(12, 0.1)

frameWidth = int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH))
frameHeight = int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT))

while True:
# Capture frame-by-frame
ret, frame = video_capture.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(30, 30),
    flags=cv2.CASCADE_SCALE_IMAGE
)

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
    #cv2.putText(frame, 'How are you', (x - 1, y - 1), cv2.FONT_HERSHEY_PLAIN,2,(0, 255, 0)) 
 #if the puttext at here, it will write the text on top of each face detected.  But I just need the text appear once.

# Display the resulting frame
cv2.imshow('Video', frame)


if len(faces) > 0:
    cv2.putText(img = frame, text = 'How are you', org = (int(frameWidth/2 - 20),int(frameHeight/2)), fontFace = cv2.FONT_HERSHEY_DUPLEX, fontScale = 3, 
                    color = (0, 255, 0))
    #print(int(frameWidth/2 - 20),int(frameHeight/2))
    #print('Found ' + str(len(faces)) + ' face(s)')

if cv2.waitKey(1) & 0xFF == ord('q'):
    break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()

您正在
putText
之前调用
imshow
,因此您将永远看不到
putText
的结果。将
imshow
语句移动到
waitKey

您正在调用
imshow
putText
之前的行,这样您将永远看不到
putText
的结果。将
imshow
语句移动到
waitKey
之前的行