ส่งภาพจากเว็บแคมไปแสดงที่เว็บบราวเซอร์ด้วย Raspberry Pi

สำหรับ Raspberry Pi เราจะใช้โปรแกรม Motion ซึ่งจะทำการสตรีมข้อมูลจากกล้องเว็บแคมไปแสดงผลที่เว็บบราวเซอร์ เราสามารถประยุกต์เอาไปใช้ทำเป็นกล้อง CCTV เพื่อเอาไว้ดูบ้านเวลาที่เราไม่อยู่บ้านก็ได้
อย่างแรกต่อเว็บแคมกับ Raspberry Pi ให้เรียบร้อย

ทำการติดตั้งโปรแกรม Motion
1 | sudo apt-get install motion |

และเหมือนเดิมถ้าหากว่าติดตั้งไม่ได้ หรือเกิดมี Error ขึ้นมา ให้ลองทำการอัพเดทแพคเกจ และลองใหม่อีกครั้งนะครับ
1 2 | sudo apt-get update sudo apt-get upgrade |
1 | sudo nano /etc/motion/motion.conf |
1 2 3 | daemon on webcam_localhost off control_localhost off |

ต่อไปทำการแก้ไข /etc/default/motion เพื่อกำหนดให้โปรแกรม Motion ทำงานเป็น Daemon Service ได้
1 | sudo nano /etc/default/motion |
1 | start_motion_daemon=yes |

จากนั้นสั่ง Start Motion Server ขึ้นมาได้เลยครับ
1 | sudo service motion start
|

เรียบร้อยแล้วครับ ทำการเปิดเว็บบราวเซอร์เพื่อดูผลงานได้เลย
ทดลองเปิดดูวิดีโอ
http://192.168.8.102:8081

ก่อนจบวันนี้ ถ้าหากว่าเราต้องการเปลียนพอร์ตที่ใช้งาน ให้ไปใช้หมายเลขพอร์ตอื่น ก็สามารถเข้าไปแก้ไขได้ที่ไฟล์ /etc/motion/motion.conf นะครับ โดยแก้ไขที่บรรทัด
1 | webcam_port 8081 |
เพิ่งเจอปัญหาว่ามันเปิดจาก Google Chrome ไม่ได้ น่าจะเป็นที่ว่าตัว motion มันใช้เทคนิค refresh ภาพ โดยเอาภาพหลายๆอันมาต่อๆกันให้ดูเหมือนเคลือนไหว เอาไว้คราวหน้าเดียวเราลองหาวิธีอื่นดูดีกว่าครับ
*อัพเดท 2013-09-16 #2
ตอนนี้สามารถแก้ไขปัญหาที่ไม่สามารถแสดงผลบน Google Chrome ได้แล้วครับ โดยให้สร้าง HTML ขึ้นมา และใส่แทก IMG โดยให้ SRC ของ IMG ชี้ไปที่ URL ของ Motion Server ครับ
1 | sudo nano /var/www/motion.html |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <!doctype html> <html> <head> <meta charset="utf-8"> <title>Motion Webcam Server</title> </head> <body> <img src="http://192.168.8.102:8081/" /> </body> </html> |
*อัพเดท 2013-09-20 #1
หลังจากทดลองเล่นมาหลายวัน พบว่าข้อมูลที่สตรีมมิ่งมาจาก motion server สามารถเปิดจาก VLC Media Player ซึ่งโปรมแกรมเล่นมัลติมีเดียแบบโอเพนซอร์ส หากใครยังไม่มีก็สามารถดาวโหลดได้จาก http://www.videolan.org/
เปิดโปรแกรม VLC Media Player และเข้าไปที่เมนู Open Network Stream

พิมพ์ URL ที่โปรแกรม motion สตรีมข้อมูลออกมา ในทีนี้คือ http://192.168.8.102:8081 จากนั้นกด Play

ภาพจากเว็บแคมของเราก็จะมาแสดงบนโปรแกรม VLC Media Player

ไม่มีความคิดเห็น:
แสดงความคิดเห็น