We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
OpenCV - loadImage based on URL? (Read 2463 times)
OpenCV - loadImage based on URL?
Mar 19th, 2010, 9:54am
 
The basic idea.

I'm loading a collection of images from flicker and as they load I want to run them through a face detection algorithm. I'm using the openCV library found here: http://ubaa.net/shared/processing/opencv/

Here is a snippet of my code. photoURL[i] is an array of strings that are exactly that, URLs of photos.




   opencv = new OpenCV(this);
   opencv.loadImage( photoURL[i], width, height );                   // open video stream PROBLEM HERE... THE URL IS NOT BEING RECOGNIZED.
   opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );  // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"

   opencv.read();
   Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );
   if (faces.length > 0){ println("There are " + faces.length + " faces.");}
   else {println("  None");}


I get an error at each iteration saying something along the lines of:

The image file 'http://farm3.static.flickr.com/blahblahblah_s.jpg' can not be found in folders, you must specify the full path instead.

I believe this means that opencv wants to read from an image that is from the folder instead of online. I thought of ways around this, like saving the image that I get from the URL to the folder, but don't know how. The save() function captures the whole screen, not just the tiny 75 by 75 image that I'm uploading. And mind you I want to upload a collection, ie. around 35.

By the way, I know my photoURL[i] string is good, because it successfully uploads the code elsewhere.

Any help or suggestions on how to deal with this problem?


Thanks so much,





Re: OpenCV - loadImage based on URL?
Reply #1 - Mar 22nd, 2010, 2:32am
 
As far as I know, OpenCV cannot read from an URL.
But OpenCV has an image buffer for an image to work on.
You have to allocate that buffer, see
http://ubaa.net/shared/processing/opencv/opencv_allocate.html
copy you image into that buffer, see
http://ubaa.net/shared/processing/opencv/opencv_copy.html
and go from there.
Re: OpenCV - loadImage based on URL?
Reply #2 - Mar 23rd, 2010, 6:23am
 
Thanks for the reply Smiley

I've tried the snippets of code, placing my URL where the examples state "niolon.jpg", but I get the same error: It asks for my photos to be placed in the sketch folder.

Am I missing something obvious here?

Thanks,
Re: OpenCV - loadImage based on URL?
Reply #3 - Mar 23rd, 2010, 7:26am
 
Ok, I was not precise enough.
1. Step: get the picture from URL
Use NOT OpenCV but Processings loadImage. See
http://processing.org/reference/loadImage_.html
2nd Step: allocate Buffer for OpenCV
See my last post
3rd step: copy the image, that you just loaded (with loadImage command) into OpenCV buffer.
See also my last post
4th step: Use OpenCV to do something with the image

good luck.
Page Index Toggle Pages: 1