Loading an axis Camera in qt with open cv - c++

I have been trying for some time to load an image from a axis 205 network cam into my qt programming using opencv running on a windows laptop. According to the cameras configuration page
The Motion JPEG image stream is fetched from the file:
http://192.168.0.90/axis-cgi/mjpg/video.cgi?resolution=640x480
the login for the camera is root for the username and pass for the password
I have tried several variations in the code but I can not get the program to display the image
VideoCapture * cap = new VideoCapture("http://192.168.0.90/axis-cgi/mjpg/video.cgi?resolution=640x480");
Mat frame;
cap->read(frame);
Everything I try results in an empty frame, Thanks for any help
~Gibby

After a bit more messing around I discovered that the correct code is
VideoCapture * cap = new VideoCapture("http://root:pass#192.168.0.90/axis-cgi/mjpg/video.cgi?resolution=640x480.mjpg");
For whatever reason the url must end in mjpg.

Related

using OpenCV to capture images, not video

I'm using OpenCV4 to read from a camera. Similar to a webcam. Works great, code is somewhat like this:
cv::VideoCapture cap(0);
cap.set(cv::CAP_PROP_FRAME_WIDTH , 1600);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 1200);
while (true)
{
cv::Mat mat;
// wait for some external event here so I know it is time to take a picture...
cap >> mat;
process_image(mat);
}
Problem is, this gives many video frames, not a single image. This is important because in my case I don't want nor need to be processing 30 FPS. I actually have specific physical events that trigger reading the image from the camera at certain times. Because OpenCV is expecting the caller to want video -- not surprising considering the class is called cv::VideoCapture -- it has buffered many seconds of frames.
What I see in the image is always from several seconds ago.
So my questions:
Is there a way to flush the OpenCV buffer?
Or to tell OpenCV to discard the input until I tell it to take another image?
Or to get the most recent image instead of the oldest one?
The other option I'm thinking of investigating is using V4L2 directly instead of OpenCV. Will that let me take individual pictures or only stream video like OpenCV?

Streaming an IP camera in OpenCV

I am trying to obtain video from an IP camera Axis 6034E using OpenCV in c++.
I can easily read stream using following simple code:
VideoCapture vid;
vid.open("http://user:password#ipaddres/mjpg/video.mjpg");
Mat frame;
while(true){
vid.read(frame);
imshow("frame", frame)
waitKey(10);
}
But my problem is, the password contain # and unfortunately it is the last charterer of the password. Any idea I will appreciate it.
I tried \# and some other encoding methods and it didn't help.

OpenCV : Open Mobotix Camera Feed

I have a Mobotix Camera. It is an IP Camera. In the API they offer us the possibility to get the feed via
http:// [user]:[password]#[ip_adress]:[port]/cgi-bin/faststream.jpg?[options]
What I've tried is to open it like a normal webcam feed :
cv::VideoCapture capture("http://...");
cv::Mat frame;
if (capture.isOpened())
// always false anyway.
while(1)
{
capture.read(frame);
cv::imshow("Hi there", frame);
cv::waitkey(10);
}
FYI : Developer Mobotix API Docs
EDIT : Now thanks to berak I just had to add &data=v.mjpg to the options :
?stream=full&fps=5.0&noaudio&data=v.mjpg
Note that in v.mjpg, only the [dot]mjpg is important, you could as well put myfile.mjpg.
Now the problem is the speed at which the feed update. I got a 2 seconds delay, plus the feed is very very slow.
And when I change the stream option for MxJPG or mxg I get a corrupted image where the bytes aren't ordering properlly.
EDIT : I tried to change the camera parameters directly with the mobotix control center but only the resolution affected my OpenCV program, without actually changing the speed at which I access the images.
for max speed use fps=0 Its in the api docs
something like
http://cameraip/cgi-bin/faststream.jpg?stream=full&fps=0
see http://developer.mobotix.com/paks/help_cgi-image.html
faststream is the mjpeg stream (for image capture) , make sure mxpeg is turned off and pick the smallest image that gives you enough resolution. i.e get it working using 640 by 480 (set it camera webgui) then increase the image size.
Note this is for image capture not video and you need to detect the beginning and end of each jpeg then copy from receive buffer into memory.
vlc can handle mxpeg ,but need to either start from command line with vlc --ffmpeg-format=mxg or set an edit option ffmpeg-format=mxg in the gui
see https://wiki.videolan.org/MxPEG
I know this post is quite old but I thought to answer for anyone else who comes across this issue. To get a stream without frame rate limitations you need to use a different CGI command:
http://<camera_IP>/control/faststream.jpg?stream=full&fps=0
As per the camera's on-line help:
http://<camera_IP>/cgi-bin/faststream.jpg (guest access)
http://<camera_IP>/control/faststream.jpg (user access)
The default limitation of the "guest" access is indeed 2 fps but it can be modified from the page Admin Menu > Language and Start Page.
A detailed description of how to retrieve a live stream from a MOBOTIX camera is available at the following link: https://community.mobotix.com/t/how-to-access-a-live-stream-with-a-video-client-e-g-vlc/202

Logitech quickcam pro 9000 Bayer capture with openCV

I'm trying to capture the raw data of the logitech pro 9000 (eg. the so called Bayer pattern). This can be achieved by using the so called bayer application, that can be found floating over the internet. It should return a 8 bit bayer pattern, but the results are quite obviously not such a pattern.
However; The image that is being streamed seems to be quite off. As can be seen in the image below, I get 2 images of the scene in a 3 channel image (meaning 6 channels in total). Each image is 1/4th of the total capture area, so it would seem that there is some kind of YUV data being streamed.
I was unable to convert this data into anything meaningful using the conversions provided by openCV. Any ideas what kind of data is being sent and (more importantly) how to convert this into RGB?
EDIT
As requested; the codesnippet that is used to generate the image.
system("Bayer.exe 1 8"); //Sets the camera to raw mode
// set up camera
VideoCapture capture(0);
if(!capture.isOpened()){
waitKey();
exit(0);
}
Mat capturedFrame;
while(true){
capture>>capturedFrame;
imshow("Raw",capturedFrame);
waitKey(25);
}
How did you get frames from stream using openCV? Can you share some code snippets? There are too many video formats in openCV for getting correct color channel and compressed data.
I think you should be able to obtain correct image frames as mentioned here :
http://forum.openrobotino.org/archive/index.php/t-295.html?s=c33acb1fb91f5916080f8dfd687598ec
This is most likely to happen if the out put data format ( width, height, bit depth, no of channels...) of camera and the data format your program expect is different.
However i could capture of logitec pro cam, simply by using
Mat img;
VideoCapture cap(0);
cap >> img;

OpenCV - Webcam does not work

I'm learning OpenCV because I want to build and program a 3D Scanner over the summer.
I bought three webcams for this purpose (two for the actual stereo images and one for texture [or as a backup]).
I tried to get a webcam's video with OpenCV. However, this does not work, as I ended up with a black screen, instead of video.
I then tried the same code with my grandmother's webcam. It worked fine.
However, I already bought 3 webcams of the type that I was planning on using to build my scanner: http://www.amazon.com/Webcam-Camera-Vision-Meeting-compatible/dp/B0015TJNEY/ref=pd_bxgy_e_img_b
I don't want to buy any new webcams.
Does anybody have any idea of why my webcams don't work with OpenCV (they work with other programs)?
How can I get OpenCV to accept my webcams?
Any suggestions would be appreciated!
Thanks
If your program pass this step , you should try a different number for cvCaptureFromCAM(0); 0 is the first web cam but maybe your's is set as 1, 2 or 3. you can also try -1 and see what happens
CvCapture *capture;
capture = cvCaptureFromCAM(0);
if (!capture)
{
printf("Error at capture");
return 1;
}