WebCam

This section contains a python example of how to grab an image from a Panasonic iPro Extreme WV-S6130 WebCam.

Download file: example_02.py

 1#!/usr/bin/env python
 2# -*- coding: utf-8 -*-
 3
 4"""
 5How to grab images from a Panasonic iPro Extreme WV-S6130 web cam
 6"""
 7
 8import os
 9import cv2
10import pathlib
11import json
12import matplotlib.pyplot as plt
13from dotenv import load_dotenv
14
15def read_json(fname):
16    with open(fname, 'r') as fp:
17        alist = json.load(fp)
18    return alist
19
20# Create a file in the home directory called access.json
21# {
22#     "p"  : "password",
23#     "u"  : "username",
24#     'ip' : "192.168.1.1" # replace with the webcam IP address
25# }
26
27
28access_fname = os.path.join(str(pathlib.Path.home()), 'access.json')
29access_dic = read_json(access_fname)
30
31try:
32
33    ret, frame = cv2.VideoCapture('http://' + access_dic['u'] +':' + access_dic['p'] + '@' + access_dic['ip'] + '/cgi-bin/mjpeg?stream=1').read()
34    if ret:
35        plt.imshow(frame)
36        plt.show()
37
38except FileNotFoundError:
39    log.error('username and password are missing. Set them in a file called: %s' % access_fname )