Skip to main content

IP camera access through python

In this tutorial we access IP camera using python.
from urllib.request import Request, urlopen
import base64
import cv2
import urllib
import numpy as np
url = 'http://192.168.0.104:8080/shot.jpg'
username = ''
password = ''
while True:
    proxy_handler = urllib.request.ProxyHandler({})
    opener = urllib.request.build_opener(proxy_handler)
    imgResp = Request(url, headers={"User-Agent": "Mozilla/5.0"})
    base64string = base64.b64encode(('%s:%s' % (username, password)).encode("utf-8")).decode("utf-8")
    imgResp.add_header("Authorization", "Basic %s" % base64string)
    r = opener.open(imgResp)
    imgNp = np.array(bytearray(r.read()), dtype=np.uint8)
    img = cv2.imdecode(imgNp, -1)
    cv2.imshow('test', img)
    if ord('q') == cv2.waitKey(10):
        exit(0)
    # all the opencv processing is done here
    cv2.imshow('test', img)
    if ord('q') == cv2.waitKey(10):
        exit(0)

Comments

Popular posts from this blog

How start Data scientist journey

(Read only if you're interested in getting into Data Science or tag, if you know someone who is) Everyday, I get inboxes from people on LinkedIn/Fb who are passionate about learning Data Science, but they don't know how to start because they have no prior knowledge on this field. The internet has a lot of useful resources that can be availed to get into this field and I thought I take out the time to share a few based on my little experience in this domain. The following is one of the lists of steps that you can follow if you want to jump into learning Data Science. 1. The initial and most important thing is to have your core concepts on machine learning to be strong. I believe that just like OOP concepts are the basic pillars for a Software Developer, same goes to ML concepts for a Data Scientist. This course is 11 weeks long, but it will develop your ML base. Therefore, this course from Andrew Ng on ML should be your first step. And as most of you already know, you...

How parse XML file Dataset using python

Parse XML file and Store data in CSV file for machine learning Algorithms. import xml.etree.ElementTree as ET import os import csv path = 'G:\salman' with open('names.csv', 'a') as csvfile:     fieldnames = ['pair_id', 'e1', 'e2', 'Sentance']     writer = csv.DictWriter(csvfile, fieldnames=fieldnames)     for filename in os.listdir(path):         if not filename.endswith('.xml'): continue         fullname = os.path.join(path, filename)         tree = ET.parse(fullname)         lst = tree.findall('sentence')         for i in lst:             i_ = i.findall('pair')             for elem in i_:                 if elem.attrib['ddi'] == 'true':                     writer.writerow({'pair_id': elem.att...