Python3 & OpenCV3 [ Part 3 : Function Video] 😝

เรียนรู้พื้นฐานคำสั่ง OpenCV : Video

จากบทความที่แล้ว เราได้สอนการจัดการกับ Image กันไปบ้างแล้ว
ครั้งนี้เราจะมาดูคำสั่งพื้นฐานในการจัดการ Videoกัน 💻

open terminal in VS Code (Ctrl + `)

workon opencv

Basic Function Video OpenCV

cv2.cvtColor(var_image/var_video, type_change_color)

  • cv2.cvtColor() : เป็นคำสั่งสำหรับเปลี่ยนสีของรูปภาพและวิดีโอ
  • จาก BGR → Gray ใช้ cv2.COLOR_BGR2GRAY
  • จาก BGR → HSV ใช้ cv2.COLOR_BGR2HSV
  • ไม่เปลี่ยนสี ใช้ 0

cv2.VideoCapture(select_camera/file_video)

  • cv2.VideoCapture() : เลือกกล้องที่เชื่อมต่อกับอุปกรณ์ ถ้าเลือกกล้องภายในใช้คำสั่ง cv2.VideoCapture(0) → โดยระบบจะเริ่มนับตั้งแต่กล้องที่ 0 (ภายใน)

Ex. cv2.cvtColor() & cv2.VideoCapture() → Live Stream

cv2.VideoWriter(file_video,fourcc, frame_per_second, (x_axis,y_axis))

  • cv2.VideoWriter() : อัดวิดีโอลงไฟล์

cv2.VideoWriter_fourcc(FourCC code)

  • cv2.VideoWriter_fourcc() : video codec
  • Fedora: DIVX, XVID, MJPG, X264, WMV1, WMV2
  • Windows: DIVX, XVID

Ex. cv2.VideoWriter() & cv2.VideoWriter_fourcc()→ Writer Video

Ex. → Play Video

……………………………………………………………………………………….

Source Code :

แล้วพบกันใหม่ Part 4เราจะมารู้จักกับ Tricks ต่างๆกัน 😵

……………………………………………………………………………………….

Nonpavit Detbun 🔋🍺

Written by

I’m Electrical Engineering. 📟 I have an interest in Web App, Mobile App, IoT and Microcontroller 🧐

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade