![]() | 1 | initial version |
I have found a work-around which is kind of hacky but it will probably work where other options have failed. It worked for me ;)
If you are able to open the stream with vlc (or other player/library) but fail to do it with opencv you can do this.
1 - Get vlc to open the http/rtsp stream from the ip camera.
2 - Set vlc to stream the source video to a file (Instructions here - http://www.ehow.com/how_11401801_stream-videos-internet-using-vlc.html).
You very likely do be able to do this step will a call to vlc executable with some parameters (Hint: you can run vlc without GUI by running cvlc).
3 - Use your preferred method of opening a file with opencv. I tested it this way (its standard video opening code):
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
const std::string video = "/path/video";
if(!vcap.open(video)) {
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
for(;;) {
if(!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
cv::imshow("Output Window", image);
if(cv::waitKey(1) >= 0) break;
}
}
Plus: this method could be improved if instead of redirecting the stream to a file, you could redirect to a device (/dev/something), and maybe opencv would be able to open it.
![]() | 2 | No.2 Revision |
I have found a work-around which is kind of hacky but it will probably work where other options have failed. It worked for me ;)
If you are able to open the stream with vlc (or other player/library) but fail to do it with opencv you can do this.
1 - Get vlc to open the http/rtsp stream from the ip camera.
2 - Set vlc to stream the source video to a file (Instructions here - http://www.ehow.com/how_11401801_stream-videos-internet-using-vlc.html).
You very likely do be able to do this step will a call to vlc executable with some parameters (Hint: you can run vlc without GUI by running cvlc).
3 - Use your preferred method of opening a file with opencv. I tested it this way (its standard video opening code):
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
const std::string video = "/path/video";
if(!vcap.open(video)) {
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
for(;;) {
if(!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
cv::imshow("Output Window", image);
if(cv::waitKey(1) >= 0) break;
}
}
Plus: this method could be improved if instead of redirecting the stream to a file, you could redirect to a device (/dev/something), and maybe opencv would be able to open it.
You can also read this stackoverflow post for more options: http://stackoverflow.com/a/7084081/1085483
![]() | 3 | No.3 Revision |
I have found a work-around which is kind of hacky but it will probably work where other options have failed. It worked for me ;)
If you are able to open the stream with vlc (or other player/library) but fail to do it with opencv you can do this.
1 - Get vlc to open the http/rtsp stream from the ip camera.
2 - Set vlc to stream the source video to a file (Instructions here - http://www.ehow.com/how_11401801_stream-videos-internet-using-vlc.html).
You very likely do be able to can probably do this step will programmatically with a call to vlc executable with some parameters (Hint: you can run vlc without GUI by running cvlc).
3 - Use your preferred method of opening a file with opencv. I tested it this way (its standard video opening code):
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
const std::string video = "/path/video";
if(!vcap.open(video)) {
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
for(;;) {
if(!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
cv::imshow("Output Window", image);
if(cv::waitKey(1) >= 0) break;
}
}
Plus: this method could be improved if instead of redirecting the stream to a file, you could redirect to a device (/dev/something), and maybe opencv would be able to open it.
You can also read this stackoverflow post for more options: http://stackoverflow.com/a/7084081/1085483