Cheat Sheet of OpenCV

TODO in progress

Image Related

TODO

Video Related

Basic video reading

video_file = "path/to/video/file.mp4"
cap = cv2.VideoCapture(video_file)
fps = cap.get(cv2.CAP_PROP_FPS)
length = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print("Video File %s ==> fps: %.2f, total: %d frames" % (video_file, fps, length))

video_start = int(0) # start from index 0
video_end = video_start + 50000 # read the first 50000 frames
cap.set(1, video_start)
for frame_index in range(video_start, video_end):
    ret, frame = cap.read()
    if not ret: break
    cv2.putText(frame, "Frame:" + str(frame_index), (20, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
    cv2.imshow("frame", frame)
    cv2.waitKey(0)

Reading with Specific Index

example: read every 5s

video_file = "path/to/video/file.mp4'"
cap = cv2.VideoCapture(video_file)
fps = cap.get(cv2.CAP_PROP_FPS)
length = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print("Video File %s ==> fps: %.2f, total: %d frames" % (video_file, fps, length))

video_start = int(0)  # start from index 0
video_end = video_start + 50000  # read the first 50000 frames
cap.set(1, video_start)

for frame_index in range(video_start, video_end):
    if not frame_index%int(5*fps)==0: continue
    else: cap.set(1, frame_index)
    ret, frame = cap.read()
    if not ret: break
    cv2.putText(frame, "Frame:" + str(frame_index), (20, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
    cv2.imshow("frame", frame)
    cv2.waitKey(0)

Convert a Video File to Images for Annotation

# install the video-cli package
pip install video-cli

video-toimg your_video.mp4  # this creates your_video/ director
No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous
Next