I have read many, many threads about streaming images over IP in OpenCV 2.3.1, but I still cannot get my program to work.
I downloaded IP Webcam for Android from https://market.android.com/details?id=com.pas.webcam&hl=en, and recently learned OpenCV to retrieve images from my Android phone camera.
Its built-in manual said that the image from the phone camera can be located at http://the.phone.ip.address:8080/shot.jpg. I have opened it from browser several times and it always looks fine. I also built OpenCV manually, with FFmpeg support.
So far I've tried
CvCapture* webcam = cvCaptureFromFile("http://192.168.1.220:8080/shot.jpg");
but it returns NULL and outputs
[image2 # 0xd701e0]Could not find codec parameters (Video: mjpeg, yuv420p)
I also tried replacing http with rtsp, but it still doesn't work. I also tried to replace the url with some other image url (one direct link to random image from Google Images, and one from localhost) and it always kills with a segfault.
Here's my full source
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
CvCapture* webcam = cvCaptureFromFile("http://192.168.1.220:8080/shot.jpg");
if(!webcam)
{
fprintf(stderr, "cannot open webcam\n");
return 1;
}
IplImage* img = cvQueryFrame(webcam);
if(!img)
{
fprintf(stderr, "cannot get image\n");
return 1;
}
cvNamedWindow("test", CV_WINDOW_AUTOSIZE);
cvShowImage("test", img);
cvWaitKey(0);
cvReleaseImage(&img);
/**/ cvReleaseCapture(&webcam); /**/
cvDestroyWindow("test");
return 0;
}
Can OpenCV really read images over IP, or am I missing something?
I'm not specifically familiar with openCV, but having spent a minute looking at the docs, two things jump out at me:-
First off, your're not dealing with a true video stream here: your android app just makes the current JPEG capture available and you have to continually re-sample it. Because it's an Image, not a Video, you should use cvLoadImage() instead.
Second, you're passing a URL, not a filename. You'll need a way to use HTTP to fetch the image to a local file before you try opening it with openCV.
I'd suggest you save a snapshot of the JPEG file locally from your browser, and then try getting your code working with that. Once you have it working from a local file, try adding the HTTP fetching stuff.
While it would be /awesome/ if that was supported, it doesn't appear to be. Note that OSes handle opening files differently from URLs (obviously) so it's not something that would be supported by default - you can't fopen() a URL. If OpenCV specifically did support it, it would be possible, but I have some evidence that they do not:
Read image from URL into OpenCV states it is not possible, and solves the problem by using an HTTP stream
This forum post from 2010 also suggests that it is not supported
This email from 2005 has a response that says the same thing.
Here's what you can do:
Download the image some other way - perhaps by using a system() call to wget, perhaps by using a library to download the file into memory
At least one source says you may use Processing's loadImage() to load from a URL.
Further searching on Roddy answer makes that I've made things work for me.
Unfortunatelly it's not nice and windows only solution. But only way to get jpg from this application is to fetch http in some way. There are many libs which can help for example libcurl, boost::asio.
I've used urlmon.lib to make things work for me:
#inlcude <opencv2\opencv.hpp>
#include <UrlMon.h>
#include <tchar.h>
#pragma comment(lib,"urlmon.lib")
int main()
{
for(;;)
{
HRESULT hr = URLDownloadToFile(NULL,_T("http://192.168.1.104:8080/shot.jpg"),
_T("D:/test.jpg"),0,NULL);
IplImage *test = cvLoadImage("D:/test.jpg");
cvShowImage("test",test);
cvWaitKey(30);
}
}
This application can also stream mjpg as I've suggested in comments. OpenCV VideoStream seems to have option to read from it as suggested Stream live video in openCv from localHost port (http://192.168.1.1:8080) and OpenCV with Network Cameras .
I've tried also this solution but get mp3 header missing. I hope that someone provide some answer with using videofeed from this application.
Related
(I am aware there is a great deal of documentation on the subject, but I am either too inexperienced to find the one that works or I have a different problem than the one documented)
I am trying to load up a simple SDL wrapper that I wrote on my Mac on Linux (Lubuntu 20.04, LXQt 0.14.1). However when SDL_Init(SDL_INIT_VIDEO) is called, the following SDL_Error() return statement is generated: No available video device. I have verified that my DISPLAY envvar is set to :0 (which is correct according to xterm) and my SDL_VIDEODRIVER is unset.
Setting my SDL_VIDEODRIVER to x11 triggers this alternative error on init x11 not available.
I am rather stumped, the only possible conclusion I could draw from this is that I am somehow not using x11 or am going about this wrong.
Here is a minimal example that triggers this error:
#include <SDL2/SDL.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
printf("%s\n", SDL_GetError());
}
I really appreciate any help I can get!
I am using the libsdl2-dev apt package for SDL2
Turns out that I had forgotten to link X11 during compilation which caused SDL_VIDEO to fail to initialise. This was resolved by using -lX11.
Thank you for the help!
I wonder what I'm doing wrong?
I want to add a file to the mpd playlist with C.
The connection works and I can play a file, which I manually put in Gnome Music Player Client for example with:
mpd_send_play(conn);
but adding the file within a C code results in an error.
Thanks for any help?
const char *path = "/home/user/foo.mp3";
mpd_send_add(conn,path);
It's really hard for us to help you if you provide this little information. I'm assuming you're using libmpdclient to try to write an MPD client.
What error are you getting?
Did you #include <mpd/client.h> or are you picking and choosing header files that that one includes for you? mpd_send_add() is a function from mpd/queue.h, are you including that header?
Could you show more code or detail your build steps so we can try to recreate your error?
i'm trying to load bitmap like this:
BITMAP *image = load_bitmap("picture.bmp", NULL);
when I test it:
if (image == NULL)
printf("No image loaded\n");
it prints No image loaded so load_bitmap doesn't work ... i have also tried absolute path but still nothing.
Im using Ubuntu and allegro 4.2
Some suggestions?
Did you try placing the image on the same location as the executable? After that is solved check this things also if still getting the error:
Is really a *.bmp file? A file of a different type can not be converted by just renaming it.
Is the file you are trying to read actually called like that? Check for spelling both in code and in the file explorer.
Does the program run correctly if executed from the file explorer or command-line but not from the IDE? If that is the case, then you should change the configuration of the workspace or project you are currently using so that the execution directory is the same as the one where the image file is located.
If all else fails then try following the steps of the tutorial again, perhaps you made something wrong. By the way, if this is your first C++ project I recommend you that instead go to more basic stuff and stick to the command-line for a while until you get the hang of the facilities the language and its libraries have to offer.
This is a project that our university is asking us to go through (asking for help on third places is not restricted)
We have to build a 3D scene in which objects are mapped with textures.
I'm stuck where I need to load a BMP file's data into the program.
We have to use a library that is already present in the system (forbidden to code it).
My request is :
Using fedora (gnome environment), is there a pre-built library into which a function that loads BMP files and returns a pointer to the payload is existent ?
EDIT : We are forbidden to install any additional libs, the lib must be a pre-built lib of Fedora.
Take a look at the GDK library and the funcion gdk_pixbuf_new_from_file. As you can see in the API you can use:
GdkPixbuf *bmp_pixbuf;
GError *error = NULL;
bmp_pixbuf = gdk_pixbuf_new_from_file ("/tmp/myfile.bmp", &error);
if (bmp_pixbuf == NULL) {
/* Error codes are GDK_PIXBUF_ERROR and G_FILE_ERROR */
}
It's important to check first the BMP support in GDK using:
$ gdk-pixbuf-query-loaders-64 | grep bmp
You need a library like libpixbufloader-bmp.so.
I don't know what library are you using to create the 3D scene, but you can get the raw pixels after load the pixbuf with gdk_pixbuf_get_pixels and then load into a surface.
Hope this help.
freeimage is the package name which does have method to upload bmp image. From online documentation at freeimage project page I can see the API:
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Load(FREE_IMAGE_FORMAT fif, const char
*filename, int flags FI_DEFAULT(0));
You can
yum install freeimage-devel
on fedora for development. Use this method and link to the library.
I'll reuse a previous answer:
Sean Barrett's stb_image.c is a stand-alone single-file public domain image loader for JPEG, PNG, BMP, TGA, PSD, GIF, HDR and PIC files.
I am trying to create a simple program using Gstreamer to take the input from a microphone and save it to a mp3 file. I keep getting
Internal data flow error
and canĀ“t seem to find the problem(I am new to Gstreamer).
Here is a link to my code:
http://pastebin.com/QDexe8Fz
Your code is not handling return codes from the functions. As a result your in the dark when it fails. Anyway in your code you forgot to link the elements. Right after line 70, also do gst_element_link_many(....);
Traditionally, the GStreamer package doesn't include support for MP3. However, you can go after codecs and plugins to make it support.