问题比比皆是:连接ip摄像头,即覆盆子pi摄像头,从覆盆子pi流到我的电脑 . 利用openCV;试图进行光学跟踪 . 我在网上发现了一些我已经修改过的开源代码,它在C中,而之前我在Python中编写了更多的OSource .
所以这里是工作的块,通知字节被解析为python中的jpg图像 . 记下urllib .
import cv2
import urllib
import numpy as np
stream=urllib.urlopen('http://<ip>:<port>/?action=stream')
bytes=''
while True:
bytes+=stream.read(1024)
a = bytes.find('\xff\xd8')
b = bytes.find('\xff\xd9')
if a!=-1 and b!=-1:
jpg = bytes[a:b+2]
bytes= bytes[b+2:]
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
cv2.imshow('Robo-View',i)
if cv2.waitKey(1) == 27:
exit(0)
现在对于C代码片段:我相信从已分配的IP地址捕获流 . 我需要找到\ xff \ xd8&\ xff \ xd9来识别jpg帧 .
int main(int argc, char* argv[])
{
//some boolean variables for different functionality within this
//program
bool trackObjects = true;
bool useMorphOps = true;
calibrationMode = true;
//Matrix to store each frame of the webcam feed
Mat cameraFeed;
//matrix storage for HSV image
Mat HSV;
//matrix storage for binary threshold image
Mat threshold;
//x and y values for the location of the object
int x = 0, y = 0;
//video capture object to acquire webcam feed
VideoCapture capture;
//Video located at this address:
const std::string vidStreamAddress = "http://<ip>:<port>/?action=stream";
//open capture object at vidstreamaddress
capture.open(vidStreamAddress);
//set height and width of capture frame
capture.set(CV_CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);
capture.set(CV_CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);
帮助将不胜感激 . 在识别解析片段的位置或者是否有可用的方法时 . 谢谢