说明:
最近的一个小任务,记录一下,希望对以后有帮助吧:
-————————————————————————————————————————————————
参考帖子
为了表达对参考帖子的敬意,先写参考的帖子的链接:
[1] OpenCV-Python视频的读取及保存:
https://blog.csdn.net/qq_25436597/article/details/79621833
[2] 用OpenCV调用IP摄像头(python版):
https://blog.csdn.net/qq_38957170/article/details/79821415
[3] opencv中VideoCapture的使用——打开网络摄像头/图像序列 :
https://blog.csdn.net/tfygg/article/details/50404861?utm_source=blogxgwz0 【备注:这个用C++实现的】
[4] IPCamera读取网络摄像头实时画面,C++实现:
https://blog.csdn.net/Da_Yuan8421/article/details/62045524?utm_source=blogxgwz0
[5] ros 编译 Python 文件
https://blog.csdn.net/light_jiang2016/article/details/55505627
—————————————————————————————————————————————————
一、先利用python实现笔记本摄像头/USB摄像头的数据的获取:
代码如下:
# coding:utf-8
# Created by Bingoren
# 27/10/2018
# YunGu, ShenZhen
# 代码适用于笔记本自身摄像头cap = cv2.VideoCapture(0)和USB外接摄像头cap = cv2.VideoCapture(1)
import numpy as np
import cv2
# 这里的0代表的是笔记本电脑的摄像头,改成1的话就是USB的摄像头了
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here,这里获取的是灰度的图像
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
结果如下:
如果想要获取的是彩色的图像,代码如下:
# coding:utf-8
# created by Bingoren
# 27/10/2018
# YunGu ShenZhen
# 代码适用于笔记本自身摄像头cap = cv2.VideoCapture(0)和USB外接摄像头cap = cv2.VideoCapture(1)
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while (1):
ret, frame = cap.read()
cv2.imshow("capture", frame)
if cv2.waitKey(1) & 0xff == ord( 'q' ):
break
cap.release()
cv2.destroyAllWindows()
结果如下:
【碎碎念:】上面这些都很基础,很惭愧自己知道的太少了,会的东西也太少了,还要好好学本领啊!
—————————————————————————————————————————————————
二、利用python和OpenCV获取监控IP摄像头的数据:
这些代码单独其实都挺简单的,没有什么难度,就是我经历的太少了,代码具体如下:
# coding:utf-8
# created by Bingoren
# 27/10/2018
# YunGu ShenZhen
import cv2
import numpy as np
# 这里就是需要把摄像头的IP读进来,
# admin的地方输入用户名;
# password的地方输入密码就ok~
# @后面的就是摄像头所在的IP地址
url = 'rtsp://admin:password@192.168.1.104:554/11'
cap = cv2.VideoCapture(url)
while(cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
# Display the resulting frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
具体运行的话IP监控摄像头涉及到隐私,就不放效果图了~
—————————————————————————————————————————————————
三、把这些代码搞到ROS框架下面去
实不相瞒,其实这一步是我最头疼的……
这一块还没有解决,该运动一会了
待续…
可能需要参考的帖子:
https://blog.csdn.net/qq_38957170/article/details/79821415
https://blog.csdn.net/Da_Yuan8421/article/details/62045524?utm_source=blogxgwz0
https://blog.csdn.net/tfygg/article/details/50404861?utm_source=blogxgwz0
https://blog.csdn.net/light_jiang2016/article/details/55505627
https://blog.csdn.net/wufan88/article/details/78811657
https://blog.csdn.net/ktigerhero3/article/details/70157582
https://blog.csdn.net/denghecsdn/article/details/78983993