Skip to main content

Posts

Windows + Pygame + VidCap

So I thought I would try out the pycam module on windows. First of all it seems windows comes with nothing, not even python. So after installing python I still needed this: http://videocapture.sourceforge.net/ and this: http://pygame.org/ftp/pygame-1.9.1.win32-py2.5.msi Vid cap itself is so easy: from VideoCapture import Device cam = Device() cam.saveSnapshot('image.jpg') To get just the most basic stuff going, for some reason the VidCap module wouldn't let me open a camera unless the size was set at (160, 120) and the Camera class seemed to change going to windows... anyhow if you want to play with this grab it from the repo here . This is using the pygame edge detect, just tried the scipy one - appears to be a problem mapping surface to numpy array... from memory there was a hack to get around something so maybe thats no longer required. The "greenscreen" example and the simple threshold. Couldn't immediatly see how to get the python wrappings for swig going...

Spyder

Enter the new matlab contender, Spyder: This would have been pretty handy over the last summer! All the pylab, scipy and numpy docs. The matplotlib integration is key. Eventually it would be awesome to see pydb and stepping through python scripts like you can for m files in matlab. But this is a huge step in the right direction! This is also my first post from Windows, good to see that Python(x,y) has been coming along nicely since I last looked at it. I will see how this Pydee (renamed to Spyder) goes on all three platforms that I now use.

Opencv source on Ubuntu 9.10

The build instructions for opencv really didn't make it clear how to go about building opencv. Well the ./configure command kept failing... So for my own reference, use the cmake method not autotools. cd ~/projects/opencv # the directory containing INSTALL, CMakeLists.txt etc.  mkdir release  cd release  cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ../ make sudo make install

Instant Messaging, Threading and Sockets

So we were given an assignment for software today. It's going to be used to teach us promala and spin and good multi-threaded software practices. The overall goal is to make a simple GUI based multi-user instant messager system in C++. I haven't used allot of concurrency before so I thought I would investigate by trying some stuff out in python. Also I haven't used sockets directly before - so wanted to have a look at them. Firstly taking a read of the Socket Programming HOWTO guide - there is plenty of information there. And also handy is the Socket documentation for python. For now I just want a echoing server that can service multiple clients at once. So the server will be the difficult part - might as well dive in there! Firstly creating a socket and echoing any data it recieves is pretty easy with this loop: while True:            data = self.conn.recv(1024)            i...

Matplotlib in Django

The official django tutorial is very good, it stops short of displaying data with matplotlib - which could be very handy for dsp or automated testing. This is an extension to the tutorial. So first you must do the official tutorial! Complete the tutorial (as of writing this up to part 4). Adding an image to a view To start with we will take a static image from the hard drive and display it on the polls index page. Usually if it really is a static image this would be managed by the webserver eg apache. For introduction purposes we will get django to serve the static image. To do this we first need to change the template. Change the template At the moment poll_list.html probably looks something like this: <h1>Django test app - Polls</h1> {% if object_list %} <ul> {% for object in object_list %} <li><a href="/polls/{{object.id}}">{{ object.question }}</a></li> {% endfor %} </ul> {% else %} <p>No polls...

Camera Histogram Demo

There is a really cool demo for opencv in C called camshiftdemo. I decided to write a version in python... The only one I could find online used opencv with ctypes , so this was a simple enough modification to get it running in more pure "swigged" python. It's in my pycam repository if anyone is interested:  http://code.google.com/p/pycam/source/browse/trunk/pycam/cam-histo.py Here are some screenshots. This is the python cam shift demo tracking the orange on the XO's logo. Now tracking the green section, you can see the histogram for the entire image shown. It is a really simple demo, and quite fun! At the Hitlab open night this was what I used to keep the kids occupied! Unlike the previous computer vision post - this doesn't use pygame at all. It would be a really good example for the XO pippy computer vision package idea however.

Facebook App

Well I thought I would have a crack at making a facebook application last weekend. Figured although theres no official python facebook api there were a few third party options so I might as well use my favorite language... I also decided that it would also be a nice opportunity to look at this Django framework thing... I also decided that it might as well run on Google's Appengine... So first I skimmed through the django tutorial again - I've only used django once before and that was just a quick look to get graphs from Matplotlib displayed on a webpage. Then I took my time going through the appengine tutorial.... There are a few things that you have to get used too in switching from django to appengine. The easiest but also most annoying is changing all the models to use Google db models. Once I was reasonably to grips with both engines I started the fun bit of getting a django app running on app engine. It is actually easy as! My mechanical engineering friend Jun is keen to h...