Powered by Blogger.

Wednesday, October 29, 2008

OpenCV Seting and working with a camera

Working in opencv with cameras is very easy, we only need a camera and our opencv libraries.



The structure that we store the camera link is CvCapture, here we store this link, then to get this link we need call to cvCaptureFromCAM function, this function need only one param, the index of the camera to be used. If there is only one camera or it does not matter what camera to use -1 may be passed.

Then this is our basic line to retrive our camera link
CvCapture* capture = cvCaptureFromCAM( 0 );

Then we only need get each frame we can capture with cam, to do this we can use the cvQuetyFrame passing as param our camera link and it return a IplImage* struct that we can show.
IplImage* frame = cvQueryFrame( capture );

With this easy lines we can get all frames we need from our camera.

Demo source
Published: By: David Millán Escrivá - 8:42 PM

Monday, October 27, 2008

Create a percent bar with CSS

To create a easy and valid percent bar or tipicall star bar we can use a schemma as you can see below.

CSS-Percent schema



With this html code:
<span class="percent"><span style="width:25%">25%</span></span>

And this stylesheet:
.percent{
display: block;
float: left;
background:url(images/percent.png) top left no-repeat;
height: 17px;
width:75px;
}
.percent span{
background:url(images/percent.png) bottom right no-repeat;
display:block;
float:left;
height:17px;
}

This is the result of our percent image:
36%45%89%66%
Published: By: David Millán Escrivá - 5:03 PM

GNUPLOT - 3d plot surface

For 3d plot gnuplot use command splot.
splot sin(sqrt((x*x+y*y)))/sqrt(x*x+y*y) t "weaves"

[caption id="attachment_37" align="aligncenter" width="300" caption="Gnuplot surface wireframe"]Gnuplot surface wireframe[/caption]

We can add the style pm3d to add a gradient surface texture
splot sin(sqrt((x*x+y*y)))/sqrt(x*x+y*y) with pm3d t "weaves"

[caption id="attachment_38" align="aligncenter" width="300" caption="Gnuplot surface 3d pm3d"]Gnuplot surface 3d pm3d[/caption]

But you can see we need more resolution, then we must set more isosamples:
set isosamples 75,75

[caption id="attachment_39" align="aligncenter" width="300" caption="Gnuplot surface with pm3d and isosample 75,75"]Gnuplot surface with pm3d and isosample 75,75[/caption]

For more info go to gnuplot page
Published: By: David Millán Escrivá - 12:12 AM

Thursday, October 23, 2008

AWK. Calculate mean, min and max

AWK is a general purpose programing language that is designed for processing text-based data. This unix command is very powerful and with it we can calculate the mean, min and max of a data stored in file.

data.txt:
10
20
50
100
200
500

awk command:
awk '{if(min==""){min=max=$1}; if($1>max) {max=$1}; if($1< min) {min=$1}; total+=$1; count+=1} END {print total/count, min, max}' data.txt

Result:
146.667 10 500
Published: By: David Millán Escrivá - 11:01 PM

New Blog



Hi, this is my new Blog, in wordpress, why? Because to maintain my old site and do it atractive need a lot of time, and I don't have time, then i installed a wordpress blog in my little server to do the task of maintain the site more easy.

I want publish more post now...
Published: By: David Millán Escrivá - 4:12 PM

Tuesday, October 21, 2008

OpenCV & OpenGL

In this tutorial we see how we can acces to OpenCV functions and use the images we process with it to use in our OpenGL program.

To use an OpenCV image (IplImage) and use it as an OpenGL textures we mus use this function.
int loadTexture_Ipl(IplImage *image, GLuint *text) {

if (image==NULL) return -1;

glGenTextures(1, text);

glBindTexture( GL_TEXTURE_2D, *text ); //bind the texture to it's array
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height,0, GL_BGR, GL_UNSIGNED_BYTE, image->imageData);
return 0;

}

This function only get data image and store it as an image Texture.

We can get a camera image and use it  to texture aplane, to do it we need a function to update the texture data, this we can do in OpenGL main loop or in glutiddleFunc as show
//En la funcion donde se actualizen los datos
frame = cvQueryFrame( capture );
if( frame ){
loadTexture_Ipl(frame, &texture);
}

Download source
Published: By: David Millán Escrivá - 11:05 PM

Flash ActionScript3 and PayPal

This is the most simply way to implement a paypal cart, this cart only have 1 item, it can be a total price of cart and one description or 1 item and quantity of items to add to cart.

You can find more info about the parameters to send to paypal in his web
myButton.addEventListener(MouseEvent.CLICK,sendToPaypal);

myButton.buttonMode=true;

function sendToPaypal(e:Event){
var paypalRequest:URLRequest = new URLRequest("https://www.paypal.com/es/cgi-bin/webscr");var variables:URLVariables = new URLVariables();

variables.cmd="_xclick";

variables.business="your-mail@business.com";

variables.item_name="Description";

variables.quantity=number-itmes-to-buy;

variables.currency_code="EUR";

variables.amount=price-item;

paypalRequest.data= variables

paypalRequest.method="POST";

try{
errorBox.htmlText="Send data to Paypal";navigateToURL(paypalRequest);

}catch (e:Error) {
errorBox.htmlText="ERROR";errorBox.htmlText=e;

}

}
Published: By: David Millán Escrivá - 8:41 PM