I want to catch video stream from IP camera in OpenCV, but OpenCV can't create VideoCapture from url, but I've got EmguCV project, where I can capture video using this url. Code:
const std::string url = "rtsp://admin:12345#192.168.6.206:554/RVi/1/1";
VideoCapture cap(url);
if (!cap.isOpened())
return -1;
namedWindow("frame", 1);
while (true)
{
Mat frame;
cap >> frame;
imshow("frame", frame);
if (waitKey(30) >= 0) break;
}
return 0;
Just for test I install OpenCV 2.9.11, and even theve everything is works.
What I do wrong?
what you need is to provide a file extension, instead of a URL. You can add the same to your URL as:
std::string url = "rtsp://admin:12345#192.168.6.206:554/RVi/1/1/x.mjpeg";
Related
I'm trying to adapt code from this page: https://www.pyimagesearch.com/2018/07/16/opencv-saliency-detection/, however that is written in Python and I'm trying to do it in C++. When I run my code it compiles, but all I see is a white screen and not any type of saliency detection going on. What's wrong?
cap.open(pathToVideo);
int frame_width = cap.get(CAP_PROP_FRAME_WIDTH);
int frame_height = cap.get(CAP_PROP_FRAME_HEIGHT);
while (true) {
Mat frame;
Mat salientFrame;
cap >> frame;
if (frame.empty()) {
break;
}
Ptr<MotionSaliencyBinWangApr2014> MS = MotionSaliencyBinWangApr2014::create();
cvtColor(frame, frame, COLOR_BGR2GRAY);
MS->setImagesize(frame.cols, frame.rows);
MS->init();
MS->computeSaliency(frame, salientFrame);
salientFrame.convertTo(salientFrame, CV_8U, 255);
imshow("Motion Saliency", salientFrame);
char c = (char)waitKey(25);
if (c == 27)
break;
}
cap.release();
The command
Ptr<MotionSaliencyBinWangApr2014> MS = MotionSaliencyBinWangApr2014::create();
should be called before the loop.
The reason is that the method processes a video, not a single image.
I would like to put an image on video and i'm wondering if it's possible in opencv without multithreading.
I would like to avoid it because in my project i am operating on RPI 0W(that's whyi don't want multithreading) .
i can't find anything about it on internet. I got some basic code in c++ . I'm new to open cv.
int main(){
VideoCapture cap(0);
if (!cap.isOpened())
{
cout << "error"<<endl;
return -1;
}
Mat edges;
namedWindow("edges", 1);
Mat img = imread("logo.png");
for (;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
imshow("edges", WINDOW_AUTOSIZE );
imshow("edges", img);
imshow("edges", frame);
if (waitKey(30) >= 0) break;
}
}
In OpenCV showing two things in the same window overwrites the previous one which I think is happening in your case.
You can use OpenCV addWeighted() function or bitwise operations.
OpenCV has good documentation on this. You can find it here
Currently, I am using OpenCV to record a lifestream from my webcam. I now want to display that in a browser. I was thinking of using VideoWriter to write the video to a file, then somehow access that file from HTML5. Is this possible? Any other suggestions?
The following is the code I have.
int main(int argc, const char * argv[]) {
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) { // check if we succeeded
std::cout << "No camera found!\n";
}
namedWindow("Window",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
imshow("Window", frame);
char keypress;
keypress = waitKey(30);
if(keypress==27) break;
}
return 0;
}
As can be seen, I am displaying the live stream in a window, but, as said, I want a browser lifestream. Thanks.
I have been trying to get openCV to read an image from my computer's webcam. The code below successfully opens the webcam (green light turns on). However, attempts to grab a frame and hence read a frame fail. I am at a loss here. Can anyone help?
Many Thanks,
Hillary
P.S. I am running Mac OS X 10.9 on a MacBook Pro. And my opencv version is 2.4.6.1
And here is the code:
#include "opencv.hpp"
using namespace cv;
int main(int, char**) {
VideoCapture cap = VideoCapture(0);
if(!cap.isOpened()){
printf("failed to open camera\n");
return -1;
}
namedWindow("edges",1);
for(;;){
if(waitKey(50) >= 0 ) break;
if(!cap.grab()){
printf("failed to grab from camera\n");
}
}
return 0;
}
You forgot to read new frames in your loop and show them! There:
for(;;){
if(waitKey(50) >= 0 ) break;
Mat frame;
if(!cap.grab()){
printf("failed to grab from camera\n");
break;
}
cap >> frame;
if(frame.empty()){
printf("failed to grab from camera\n");
break;
}
imshow("edges", frame);
}
I've 4 Axis IP cams. I need a code to capture image from those cams. I've opencv code to capture image from USB cams but I don't kno how to capture from IP cams.
int main()
{
Mat frame;
namedWindow("video", 1);
VideoCapture cap("http://150.214.93.55/mjpg/video.mjpg");
while ( cap.isOpened() )
{
cap >> frame;
if(frame.empty()) break;
imshow("video", frame);
if(waitKey(30) >= 0) break;
}
return 0;
}
no idea, how your urls look like, but opencv seems to insist, it has to end with mjpg.
so if it doesn't, the trick is to append a dummy parameter:
http://my/cool/ip-cam.ie?dummy=video.mjpg
if you need to open all 4 cams at once, you need a VideoCapture for each one:
VideoCapture cap1("url1");
VideoCapture cap2("url2");
VideoCapture cap3("url3");
VideoCapture cap4("url4");