标签:creat 预览图 source url ret release test iss 技术
分类,检测,分隔
深度学习 海量数据
边缘计算
CS231n 李飞飞教授 公开课
原始论文
https://github.com/opencv/opencv
Homepage:
Q&A forum: http://answers.opencv.org
Issue tracking: https://github.com/opencv/opencv/issues
pip换源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip install opencv-python
#当前查看版本
import cv2
cv2.__version__
import cv2
cap = cv2.VideoCapture(0)
cap.open(0)
while cap.isOpened():
flag, frame = cap.read()
cv2.imshow(‘my_window‘,frame)
key_pressed = cv2.waitKey(60)
print(‘键盘被按下的键是:‘,key_pressed)
if key_pressed == 27:
break
cap.release()
cv2.destroyAllWindows()
#边缘检测
import cv2
#cap = cv2.VideoCapture(0)
import numpy as npcap = cv2.VideoCapture(0,cv2.CAP_DSHOW)
cap.open(0)
while cap.isOpened():
flag, frame = cap.read()
if not flag:
break
key_pressed = cv2.waitKey(60)
print(‘键盘被按下的键是:‘,key_pressed)
frame = cv2.Canny(frame,100,200)
frame = np.dstack(frame,frame,frame)
cv2.imshow(‘my_window2‘,frame)
if key_pressed == 27:
break
cap.release()
cv2.destroyAllWindows()
#CannyScanV1.py
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
#import numpy as npcap = cv2.VideoCapture(0,cv2.CAP_DSHOW)
cap.open(0)
while cap.isOpened():
flag, frame = cap.read()
if not flag:
break
key_pressed = cv2.waitKey(60)
print(‘键盘被按下的键是:‘,key_pressed)
frame = cv2.Canny(frame,100,200)
frame = np.dstack((frame,frame,frame))
cv2.imshow(‘my_window2‘,frame)
if key_pressed == 27:
break
cap.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
# get a frame
ret, frame = cap.read()
# show a frame
cv2.imshow("capture", frame)
if cv2.waitKey(1) & 0xFF == ord(‘q‘):
break
cap.release()
cv2.destroyAllWindows()
#CannyScanV1.py
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
cv2.imshow(‘frame‘,gray)
if cv2.waitKey(1) & 0xff == ord(‘q‘):
break
cap.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
#import numpy as npcap = cv2.VideoCapture(0,cv2.CAP_DSHOW)
cap.open(0)
while cap.isOpened():
flag, frame = cap.read()
if not flag:
break
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
gray = cv2.blur(gray,ksize = (5, 5))
grayframe = cv2.Canny(gray,100,200)
frame = cv2.Canny(frame,100,200)
##frame = np.dstack(frame,frame,frame)
cv2.imshow(‘my_window‘,frame)
cv2.imshow(‘my_window2‘,grayframe)
if cv2.waitKey(1) & 0xff == ord(‘q‘):
break
cap.release()
cv2.destroyAllWindows()
#SmileCaptureV1.py
import cv2
#人脸检测 眼睛检测,微笑检测
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades+‘haarcascade_frontalface_default.xml‘)
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades+‘haarcascade_eye.xml‘)
smile_cascade = cv2.CascadeClassifier(cv2.data.haarcascades+‘haarcascade_smile.xml‘)
cap = cv2.VideoCapture(0)
while(True):
ret,frame = cap.read()
faces = face_cascade.detectMultiScale(frame,1.3,2)
img = frame
for (x,y,w,h) in faces:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
face_area = img[y:y+h,x:x+w]
eyes = eye_cascade.detectMultiScale(face_area,1.3,10)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(face_area,(ex,ey),(ex+ew,ey+eh),(0,255,0),1)
smiles = smile_cascade.detectMultiScale(face_area,scaleFactor = 1.16,minNeighbors=65,minSize=(25,25),flags = cv2.CASCADE_SCALE_IMAGE)
for (ex,ey,ew,eh) in smiles:
cv2.rectangle(face_area,(ex,ey),(ew+ex,ey+eh),(0,0,255),1)
cv2.putText(img,‘Smile‘,(x,y-7),3,1.2,(0,0,255),2,cv2.LINE_AA)
cv2.imshow("frame2",img)
if cv2.waitKey(5) & 0xff == ord(‘q‘):
break
cap.release()
cv2.destoryAllWindows()
#
import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("无法打开摄像头")
exit()
while True:
ret, frame = cap.read()
if not ret:
print("无法打开摄像头")
break
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
cv2.imshow("frame_window",gray)
if cv2.waitKey(1) == ord(‘q‘):
break
cap.release()
cv2.destroyAllWindows()
# VedioCapv1.py
import cv2
cap = cv2.VideoCapture("test.mp4")
if not cap.isOpened():
print("无法打开视频")
exit()
print(‘WIDTH‘,cap.get(3))
print(‘HIGTH‘,cap.get(4))
while True:
ret, frame = cap.read()
if not ret:
print("无法打开摄像头")
break
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
cv2.imshow("frame_window",gray)
if cv2.waitKey(25) == ord(‘q‘):
break
cap.release()
cv2.destroyAllWindows()
import numpy as np
import cv2 as cv
cap = cv.VideoCapture(0)
fourcc = cv.VideoWriter_fourcc(*‘DIVX‘)
# Define the codec and create VideoWriter object
# 指定输出文件,fourCC视频编码,FPS
out = cv.VideoWriter(‘output.avi‘,fourcc,20.0,(640,480))
while cap.isOpened():
ret,frame = cap.read()
if not ret:
print("无法打开摄像头")
break
frame = cv.flip(frame,0) ## 翻转视频
out.write(frame)
cv.imshow(‘frame‘,frame)
if cv.waitKey(1) == ord(‘q‘):
break
cap.release()
out.release()# 若注释掉,没有预览图片
cv.destoryAllWindows()
标签:creat 预览图 source url ret release test iss 技术
原文地址:https://www.cnblogs.com/pailang-lee/p/14353960.html