#coding: utf-8
# ////////////////////////////////////////////////////////////////////////////
# ///【CV2 カメラキャプチャー】 ///
# ////////////////////////////////////////////////////////////////////////////
if "__file__" in globals():
import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
import cv2
if __name__ == "__main__":
folder_select = "16S"
video_select = "SD"
folder_path = "d:\\VisualStudio2017\\Python3.5_GPU\\test_dataset\\Nogizaka_" + folder_select
mp_path = "c:\\Photo\\nogizaka46-" + video_select + ".mp4"
source_name = "outvideo.mp4"
write_name = "CV2_CASE2_N" + folder_select + "_N46" + video_select + "_stramVideos.mp4"
face_cascade = cv2.CascadeClassifier("C:\\opencv-3.4.1\\sources\\data\\haarcascades\\haarcascade_frontalface_alt2.xml")
cap = cv2.VideoCapture(mp_path)
fps = int(cap.get(cv2.CAP_PROP_FPS)) # カメラのFPSを取得
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # カメラの横幅を取得
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # カメラの縦幅を取得
fourcc = cv2.VideoWriter_fourcc("m", "p", "4", "v") # 動画保存時のfourcc設定(mp4用)
outFilename = write_name
video = cv2.VideoWriter(outFilename, fourcc, fps, (w, h)) # 動画の仕様(ファイル名、fourcc, FPS, サイズ)
cnt = 0
while True:
ret, img = cap.read()
try:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)
for x, y, w, h in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.imshow("video image", img)
cap.release()
cv2.destroyAllWindows()
(py37) d:\VisualStudio2017\Python3.5_GPU\DeZero\steps>pip install opencv-python
Requirement already satisfied: opencv-python in c:\users\yamin\anaconda3\envs\py37\lib\site-packages (4.6.0.66)
Requirement already satisfied: numpy>=1.14.5 in c:\users\yamin\anaconda3\envs\py37\lib\site-packages (from opencv-python) (1.21.6)
(py37) d:\VisualStudio2017\Python3.5_GPU\DeZero\steps>pip install opencv_python
Requirement already satisfied: opencv_python in c:\users\yamin\anaconda3\envs\py37\lib\site-packages (4.6.0.66)
Requirement already satisfied: numpy>=1.14.5 in c:\users\yamin\anaconda3\envs\py37\lib\site-packages (from opencv_python) (1.21.6)