cell programming

Just another WordPress.com weblog

OpenCV cvCaptureFromAVI error in Ubuntu 9.04

Recently I have installed Ubuntu Jaunty (v 9.04). I have developed some projects using OpenCV api and I have realized the cvCaptureFromAVI function wasn’t working as expected. At first I thought it had some relation with the video codec, but after converting (in Windows) the video used to an uncompressed video, this was discarded.

Then, I searched the web looking for some kind of information, and finally I found this link: http://ubuntuforums.org/showthread.php?p=7208937 in which the problem is detailed and one really easy sollution is shown.

That solution is posted here by  Gijs Molenaa: http://gijs.pythonic.nl/blog/2009/may/3/getting-video-io-working-opencv-and-ubuntu-jaunty-/

He has solved the problem fixing the sources and compiling them. He has created the .deb files and allocated them in a server. The fix in my laptop has been a piece of cake.

  • Modify my /etc/apt/sources.list to add     deb http://ppa.launchpad.net/gijzelaar/opencv/ubuntu jaunty main
  • Import the keyserver sudo apt-key adv –recv-keys –keyserver keyserver.ubuntu.com cafc44ee7f39098ce6ec229cca70e6a9087475a0
  • apt-get update
  • Update the opencv packages

Once the opencv packages has been updated the function works fine.

Thanks a lot to Gijs Molenaa  :)

May 24, 2009 Posted by Javier Sánchez Egido | General | | 3 Comments

Remote Desktop YDL6

Sometimes we can’t be physically accesing a computer due to several reasons and in those moments we wish be there. If that is the case we could use remote desktop to access the computer. I am explaining in this post how to access a Yellow Dog Linux 6.

The main prerequisite is vncserver to be installed, so if it is not installed the first step is to install it.

The next step is to launch a console and launch vncserver.

[jsanchez@localhost ~]$ vncserver

You will require a password to access your desktops.

Password:

Verify:

New ‘localhost.localdomain:1 (jsanchez)’ desktop is localhost.localdomain:1

Creating default startup script /home/jsanchez/.vnc/xstartup

Starting applications specified in /home/jsanchez/.vnc/xstartup

Log file is /home/jsanchez/.vnc/localhost.localdomain:1.log

A directory named .vnc has been created in our home folder. This folder now contains a file storing the password needed for remote access (encrypted) and a startup script.

The startup script contains the following lines.

[jsanchez@localhost ~]$ more ~/.vnc/xstartup

#!/bin/sh

# Uncomment the following two lines for normal desktop:

# unset SESSION_MANAGER

# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

xsetroot -solid grey

vncconfig -iconic &

xterm -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &

twm &

After executed the vncserver command and entered the remote access password the server listens in the specified display. The display is the number that apears after the ip or hostname. To find out the display the server is atached have a look to the log name.

Log file is /home/jsanchez/.vnc/localhost.localdomain:1.log

You can use then a vncviewer. In the server text box you have to introduce the ip host followed by : plus display number.  For example:            192.168.1.28:1

To test vncserver I have use Ultr@vnc in a windows xp laptop. I have capture the screen with the initial desktop.

EscritorioTWM vncviewer YDL 6

In my opinion this desktop is not very friendly, so I have changed my startup script to initiate an alternative session.

The way to change the desktop is to edit the script and change the last line. Instead of using twm we can use startkde (for  kde users) or gnome-session (for gnome users). I have used the last one.

#!/bin/sh

# Uncomment the following two lines for normal desktop:

# unset SESSION_MANAGER

# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

xsetroot -solid grey

vncconfig -iconic &

xterm -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &

gnome-session &

<center>

<a href=”http://www.flickr.com/photos/egido/3202731159/” title=”Escritorio Gnome vncviewer YDL6 by Javier Sánchez Egido, on Flickr”><img src=”http://farm4.static.flickr.com/3337/3202731159_cdeb27081a.jpg” width=”500″ height=”373″ alt=”Escritorio Gnome vncviewer YDL6″ border=”0″ /></a>

</center>

We can launch the vncserver command several times, but note that have a server launched spends resources and the ps3 has not enought memory to handle it.

If we wish to kill one svnserver using an especific display we can use the following command (killing display 2).

svnserver –kill :2

January 17, 2009 Posted by Javier Sánchez Egido | General, Linux | , | No Comments Yet

Compilation under ps3

Recently the research group Gavab bougth a PlayStation 3 for research. After installed Yellow Dog and the Cell Sdk 3.0 the next step was compiling on command line.

Previously I was compiling the c++ projects using eclipse, cdt and the cell broadband engine sdk in a X86 Fedora Core 6 machine.

The next goal is compile the c++ aplications in conjunction with opencv (in this case CVCell). I tried to compile it within the eclipse sdk but it wasn’t possible because I couldn’t fix all the dependencies (64 bits libraries were needed).

So, I copied two simple single sources (ppu and spu) in the same directory in the PS3 and tried to compile it. After a few tries(I wish it was a few tries :-(   ) I could run the binariy sucessfully.

The original code was intended to perform simd operations in order to test the right understanding of these instructios. I cleand the code resulting a similar code to a Hello World example.

PPE CODE

#include <stdio.h>
#include <stdlib.h>
#include <libspe2.h>
#include <pthread.h>
#include <math.h>
#include <sys/time.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>

typedef struct {
unsigned int id_spe   __attribute__ ((aligned (16)));
} context;

extern spe_program_handle_t Vec_Test_SPU;

typedef struct ppu_pthread_data {
spe_context_ptr_t spe_ctx;
pthread_t pthread;
unsigned int entry;
void *argp;
} ppu_pthread_data_t;

void *ppu_pthread_function(void *arg)
{
ppu_pthread_data_t *datap = (ppu_pthread_data_t *)arg;
if (spe_context_run(datap->spe_ctx, &datap->entry, 0, datap->argp, NULL, NULL) < 0)
{
perror (“Failed running context\n”);
exit (1);
}
pthread_exit(NULL);
}

ASD
const unsigned int MAX_SPE_THREADS = 8;

int main()
{

ppu_pthread_data_t datas[MAX_SPE_THREADS];
context ctxs[MAX_SPE_THREADS] __attribute__ ((aligned (16)));

//Obtenemos el número de hilos a crear
unsigned int spe_threads = spe_cpu_info_get(SPE_COUNT_USABLE_SPES, -1);
if (spe_threads > MAX_SPE_THREADS)
spe_threads = MAX_SPE_THREADS;

unsigned int i;
// Create multiple SPE threads
for (i=0; i<spe_threads; i++) {

// Create SPE context
if ((datas[i].spe_ctx = spe_context_create (0, NULL)) == NULL) {
perror (“Failed creating context”);
exit (1);
}
// Load SPE program into the SPE context
if (spe_program_load (datas[i].spe_ctx, &Vec_Test_SPU)) {
perror (“Failed loading program”);
exit (1);
}
// Initialize context run data
datas[i].entry = SPE_DEFAULT_ENTRY;
datas[i].argp = &ctxs[i];

// Create pthread for each of the SPE conexts
if (pthread_create (&datas[i].pthread, NULL, &ppu_pthread_function,
&datas[i])){
perror (“Failed creating thread”);
}
}
// Wait for all the SPE threads to complete.
for (i=0; i<spe_threads; i++) {
if (pthread_join (datas[i].pthread, NULL)) {
perror (“Failed joining thread”);
exit (1);
}
}

printf(“FIN PPU\n”);

return (0);
}

SPE CODE

#include <stdio.h>

int main(unsigned long long spe_id, unsigned long long parm)
{
printf(“END SPU\n”);
return 0;
}

In order to compile the sources the following commands are needed.

spu-gcc spe_program.c -o spe_program

ppu-embedspu Vec_Test_SPU spe_program lib_spu_program.a

ppu-gcc ppe_program.c lib_spu_program.a -lspe2 -o ppe_program

September 22, 2008 Posted by Javier Sánchez Egido | Cell, General | , , | No Comments Yet