@nobu6787 (nobunobuta)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

fourccとは?

opencvのタイムラプス生成が上手くいきません。
尚、python実践データ分析100本ノックのノック88を参照しています。

<コード>
import cv2

print("タイムラプス生成を開始します")

映像取得

cap = cv2.VideoCapture("mov/mov01.avi")
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

hog宣言

hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
hogParams = {'winStride': (8,8), 'padding': (32,32), 'scale': 1.05, 'hitThreshold':0, 'finalThreshold':5}

タイムラプス作成

movie_name = "timelapse.avi"
fourcc = cv2.VideoWriter_fourcc('X', 'V', 'I', 'D')
video = cv2.VideoWriter(movie_name,fourcc, 30, (width,height))

num = 0
while(cap.isOpened()):
ret, frame = cap.read()
if ret:
if (num%10==0):
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
human, r = hog.detectMultiScale(gray, **hogParams)
if(len(human)>0):
for(x, y, w, h) in human:
cv2.rectangle(frame, (x,y),(x + w, y + h), (255,255,255), 3)

        video.write(frame)
else:
    break

        num = num + 1
video.release()
cap.release()
cv2.destroyAllWindows()
print("タイムラプス生成を終了しました")

<エラー>
error Traceback (most recent call last)
()
16 movie_name = "timelapse.avi"
17 fourcc = cv2.VideoWriter_fourcc('X', 'V', 'I', 'D')
---> 18 video = cv2.VideoWriter(movie_name,fourcc, 30, (width,height))
20 num = 0
21 while(cap.isOpened()):

error: OpenCV(4.5.5) :thumbsdown: error: (-5:Bad argument) in function 'VideoWriter'

Overload resolution failed:

  • Can't parse 'frameSize'. Sequence item with index 0 has a wrong type
  • VideoWriter() missing required argument 'frameSize' (pos 5)
  • VideoWriter() missing required argument 'params' (pos 5)
  • VideoWriter() missing required argument 'frameSize' (pos 5)

エラーがvideo = cv2.VideoWriter(movie_name,fourcc, 30, (width,height))を指していること、
コード中の'fourcc'に青波線があり、カーソルを合わせると"fourcc":unknown wordとなることから
この部分が良くないのはおおよそ検討がつくのですが、なかなか解決しません。
エラーの意味も合わせてご教授いただけると幸いです。
どうぞよろしくお願いします。

0 likes

No Answers yet.

Your answer might help someone💌