買的這個攝像頭蝠咆,應(yīng)該不是河欢康本家的北滥,但協(xié)議通用
https://item.taobao.com/item.htm?_u=b2020hgjkb441f&id=635662827249
上來先把電源線剪了改安德森口,正極剪開后有兩根線闸翅,粗的那個是夜視的紅外 LED 燈的供電再芋,細的是攝像頭本身的,可以把兩根線搓到一起都接到 12V 上
通電后剛開始不知道攝像頭 IP坚冀,也沒有說明書啥的
后來發(fā)現(xiàn)可以用杭檬辏康的 SADP 軟件找到局域網(wǎng)中的所有攝像頭
軟件下載在這里 https://www.hikvision.com/cn/download_more_393.html
攝像頭通電后應(yīng)該會有咔嚓的一聲,是攝像頭模組的光學(xué)濾鏡初始化的聲音记某,網(wǎng)線接到局域網(wǎng)中用 SADP 搜索就能找到攝像頭司训,改成局域網(wǎng)下的 IP 地址
最新版 Chrome 訪問會提示不支持,只能用 IE 來訪問液南,是個特別老舊的頁面壳猜,但能看到圖像
攝像頭使用的是 rtsp 視頻串流,地址格式如下:
rtsp://[username]:[password]@[ip]:[port]/[codec]/[channel]/[subtype]/av_stream
username: 用戶名滑凉,初始admin统扳。
password: 密碼,初始admin畅姊。
ip: 為設(shè)備IP咒钟,例如 192.168.1.103。
port: 端口號若未,初始/默認554朱嘴,若為默認可不填寫。
codec:h264粗合、MPEG-4萍嬉、mpeg4
channel: 通道號,起始為1舌劳。例如通道1帚湘,則為ch1。
subtype: 碼流類型甚淡,主碼流為main大诸,輔碼流為sub(主碼流清晰用于本地,子碼流用于網(wǎng)絡(luò)傳輸)贯卦。
For example:
rtsp://admin:admin@192.168.1.103:554/h264/ch1/main/av_stream
(https://blog.csdn.net/patrick_starrr/article/details/93858412)
用 VLC 軟件资柔,在媒體 -> 網(wǎng)絡(luò)流媒體下面輸入 rtsp 的地址就可以看到畫面
下面是用 Python 顯示,
import cv2
url = "rtsp://admin:admin@192.168.1.37:554/h264/ch1/main/av_stream"
vcap = cv2.VideoCapture(url)
while(1):
ret, frame = vcap.read()
cv2.imshow('VIDEO', frame)
cv2.waitKey(1)
就可以用 opencv 讀到畫面
接下來用 Flask 串流畫面到瀏覽器上撵割,用的網(wǎng)上的案例程序贿堰,語法比較神奇:
(https://medium.datadriveninvestor.com/video-streaming-using-flask-and-opencv-c464bf8473d6)
import cv2
class VideoCamera(object):
url = "rtsp://admin:admin@192.168.1.37:554/h264/ch1/main/av_stream"
def __init__(self):
#capturing video
self.video = cv2.VideoCapture(self.url)
def __del__(self):
#releasing camera
self.video.release()
def get_frame(self):
#extracting frames
ret, frame = self.video.read()
# encode OpenCV raw frame to jpg and displaying it
ret, jpeg = cv2.imencode('.jpg', frame)
return jpeg.tobytes()
#!/usr/bin/env python
from flask import Flask, render_template, Response, url_for
app = Flask(__name__)
@app.route('/')
def index():
return '''<html>
<head>
<title>Video Streaming Demonstration</title>
</head>
<body>
<h1>Video Streaming Demonstration</h1>
<img src="'''+url_for('video_feed')+'''">
</body>
</html>
'''
def gen(camera):
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
@app.route('/video_feed')
def video_feed():
return Response(gen(VideoCamera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)