Tuesday, 31 December 2013

New use for old hardwarEee

While playing with webcams and computer vision is fun in it's own right, I've been thinking about the uses of my these programs, and came to the conclusion that they need to be run on machines that won't be a huge loss if they go missing or get stolen, I have an old Eee pc 701sd lying around that fits the bill nicely. An alternative would be a Raspberry Pi system, with an external webcam, but my budget doesn't extend to that at the moment.

The Xandros that comes on the Eee it is not well suited to development, and is well out of date these days, so I set about finding a new compact distro for it, and settled on Lucid Puppy, a very light weight, compact, ubuntu compatible build that can be run from usb.

I started using the universal installer to make a usb to trial it on - an exercise of it's own, you need to load bios each time, look at the hard drive order, save, then press esc, and choose the usb...
LuPu ran well, quite fluid, despite the dreadful specs of that machine with a external mouse and keyboard, and running a 17" monitor powered by an able-hd (www.able-hd.com) adaptor.

Because of the effort required to boot to USB I chose to install LuPu onto the sdd, removing the previous installs, and have finally got to the point where i can write, and compile c programs, so there is more to come.

'Copter update

There hasn't been a lot of progress on the copter over the last few weeks. I did ordered and recieve some more bits and pieces this month, from the international warehouse at Hobby King. I ordered some soldering gear, a few ESCs, and some more connectors, so that I can modify the design to enable the swapping of any and all components if they are damaged following a crash.

The wiring is finished, I need to program the ESC's, but that's about 5 minutes work, and I want to add a few good LEDs from an old headlamp to it on a 5v loom so that it can be flown in the dark. The plan is a single bright LED off the front, another broad beam pointing down, and a pair of red ones on the back rotors.

Still to go is the building of the frame, and to get a new flight controller. They agreed to do it under warranty, but it has been superseded by the KK2.1, which is not yet in the Australian warehouse. After new year I'll ask for credit and get it shipped from the international website.

update 6/1/14:
Just sent the email to them... hopefully I'll get a new board in a week or so

update 10/1/14:
They can't change which model I recieve, so they gave me $32 credit, and I bought the $30 KK2.1(which is now in Australia), plus $9.99 shipping... Not entirely happy, but at least something is happening.

Seemed like they didn't understand that it wouldn't be coming into stock, and that the 2.1 was a new model, despite the fact that I said that in both emails

Friday, 13 December 2013

Time capsules and time lapses

Occasionally I use my Contour camera to record time lapses, generally of LAN parties, but the usual clouds and landscapes as well. The only issue with the contour is that the battery life is not great, about 3 hours taking photos every 15 seconds. One solution seemed to be that I could instead use the webcam on my laptop, or another device to record such events.
I also wanted to be able to analyse the images as they were taken so that ones without data could be discarded. This acts like the time capsules in police cars, if something of consequence occurs the computer records the last image, and several into the future on disk. otherwise it discards them.
This has potential if i can wire it to an external camera for use at Kambah to track down the vandals, but was mostly just a fun exercise.

I used matlab to do the coding, although i may migrate to another language to create a standalone program.

For once it was easy to program, taking just one evening to get it to a working version, but enough of that. Here's the code:
function Webcam % acts as an image logger for my hp computer, if anything in the image
% moves substantially, or the mean brightness of any column varies, then it
% takes that picture, and 15 to follow and writes them to a folder with the
% current date.
clc
clear
beep;
vid = videoinput('winvideo',1,'YUY2_640x480');
 set(vid,'ReturnedColorSpace','grayscale');
start(vid)
mkdir(date)
go = 1;
beep;
pause(3)
beep;
pause(1)
beep;beep;
 OldPic = getsnapshot(vid);
    pause(4);
crimcount=1;
while go
    pic = getsnapshot(vid);
    % comparisons
 
    olMean = mean(OldPic); % list of column means for the old image
    NewMean= mean(pic);
    % normalise them
    olMean = olMean*mean(NewMean)/mean(olMean);
    if min(olMean>0.95*NewMean)||min(olMean>1.05*NewMean)
        change = 0; % No change from previous image
    else
        change = 1; % Change from previous image
        %figure; imshow(pic);
     
        image = 1; % reset image count
        imagename=[date '/culprit' num2str(crimcount),num2str(image,'%02d'),'.jpg'];
        imwrite(pic, imagename)
     
        for i = 1:15
            pic = getsnapshot(vid);
            image = image+1;
            imagename=[date '/culprit' num2str(crimcount),num2str(image,'%02d'),'.jpg'];
            imwrite(pic, imagename)
            pause(2)
        end
        crimcount=crimcount+1;
    end
 
   pause(3);
    OldPic = pic;
 
end


To reduce processing I used grayscale images.  They are compared as a mean value of the same column in each image, with a tolerence of 5%.

This makes it less sensitve than a region, or pixelwise comparison, but given that humans tend to move horizontally, and cover a large portion of a column this seemed like a good option. in addition the movement of the sun is largely vertical, so it should be ignored.

When a detection is made, the program writes the picture to a file, and then takes another 15 at ~2 second intervals, before returning to it's standby mode, looking for changes at 8 second intervals.

The program stores the images in a new folder with todays date, and numbers them #xx for the detection number, with xx being the picture the current sequence.

By running it from dropbox the files can be immediately uploaded to a cloud, allowing an offsite backup, as well as real time notifications. So far it has been running for 4 hours in m room, with 1 good detection, and zero false ones. The undetected ones I have no evidence for, but I suspect they are also absent, this will be ivestigated further this evening.


Saturday, 23 November 2013

Things I'm looking to do

There are a few things on this list at the moment, as I haven't had the time, or money for the last few months.

I want to have a play with both the Raspberry Pi and Arduino systems... haven't really got a plan for the Arduino though, but there are a few options for the Pi:

- A car media manager, combining a few gig of music, and a bluetooth dongle, The Pi can supposedly create it's own hotspot and act as an apple airport system. This will allow my, or other people to stream music to it, which it can play through the stereo. If I don't want to use the phone to stream podcasts, I can use the inbuilt music to play.

- A similar idea, but over wifi, and able to be streamed to by a pc as well... I haven't seen any writeups of this, but it seems like it should be doable. This will allow me to use the tablet to watch hockey, while using the better speakers - and move more than a meter away while I do so. Ideally this would become 2 or more speakers, in different rooms, with a way to switch between all/ some/ one of them.


I also have plans to build a tricopter that is stable, for the purposes of cave exploration - a long term goal would be to use it to generate a 3d map of the cave system using computer vision, or other technology. But even with a manual control system it will be a fun way to get wetline/highline footage, and some cool climbing shots.

And I have the PCB for a Nixie clock that I got from kickstarter:  http://www.kickstarter.com/projects/8807675/nixie-tube-clock-project, so it seems like a bit of soldering is in my future once I obtain the $100 or so worth of components, fortunately the board is already programmed, so it's a simple matter of building the board and adding power, and making a cool case to make a nice steampunk clock.

Tricopter Progress

Spontaneous Projects is a chronicle of all of my projects, a reference for me, and a way to prevent others from making the same mistakes. 

So, last week I ordered $330 worth of RC equipment from HobbyKing's Australian warehouse to build a Tricopter, with the intention of using it as a mobile filming platform.

At the moment I'm only partway through the build, having only completed parts of the electronics, as the Flight Controller mainboard arrived with an out-of-whack y-gyro which prevents it from powering up properly. It did allow me to test the transmitter/receiver components, and I was able to test the motors independently, but the full build will have to wait until the board gets replaced - hopefully under warranty, but I'll buy another one if need be.

I found the following sites invaluable in the planning of this project, and the component selection:
http://www.averticalview.com/files/tricopter_build.pdf
http://rcexplorer.se/projects/2011/09/the-tricopter-v2-5/
The latter also links to some interesting First Person View transmitters which may be applied further in the future, once I have the money to build such a setup.

I ordered all the components to build a quadcopter, but the plan is to start with a tri, with some spare parts, and only make a quad if it won't lift a set of ay-up lights and some filming equipment.

Parts list:
Parts list -- you only need 1 pack of MM servo leads (10cm), and for a quad I recommend another 10 pack of bullet connectors. 

In addition to this parts list a 12V power supply is required, I happen to have one, and the charger uses clips, so the exact power supply is not important. The KK2 FC board has an in-built battery tone as I understand it, so the battery monitor isn't required, although I will likely use it to monitor batter state prior to flights as it has a 4 state indicator, rather than the 2 state of the FC. Likewise the UBEC is probably surplus, as a few extra wires could power the receiver off a speed controller.

The basic wiring diagram is shown below, in hindsight I'd use the x60 connectors on all 12v connections in order to allow changes of components, and bullets on all of the motor connections.

I'll go through the exact input and output connections in a later post when I can check them, as well as a few pictures of the build.

Two team +/- logger

Spontaneous Projects is a chronicle of all of my projects, a reference for me, and a way to prevent others from making the same mistakes. 

Despite the number of draw backs of +/- (goals for - goals against while the player is on the ice) as a stat for hockey , it works as an indication of a players performance if it's looked at in comparison to the rest of the team, and as a long term average.

Given that I am usually trying to manage and coach both benches, recording this by hand is tricky.

I found a  few loggers spread across the interwebs, but they suffered from a few drawbacks: generally they had fixed, and small team sizes, and could only be used for a single team. So I decided to write my own for my win 8 tablet.

Full program and VS source:
https://www.dropbox.com/s/7chfwo0mlyv7a48/PM1.2.rar

Given that the primary purpose was a graphical front end it seemed easier to use VB, despite having no prior experience in the language. The original program was designed to be as simple as possible, just select the players on the ice, and hit the home or away goal.
Setting the Player names and numbers, follow the convention if you are looking to export the data

Main page, select the players on the ice, and choose home or away goal. Reset after goal deselects all players after a goal is scored. Save writes the text file with the current date. The check box above quit is required in order to exit, so that you can't exit unintentionally.

Output text file to be imported into Excel

Like many such projects once the basic functionality was working, it suffered from expanding scope, changing the team colours, adding the players separately to the main screen,  and exporting the data as a comma separated text file in such a way that it can be imported into Excel for further analysis




Still to be added is an import function, to make roster be editable ahead of time, other than that it works as required, and with full rosters set, and lines being at least partially set it is probably possible to log both teams at once. The 2 times I've tried I've struggled, but the hope is that I can hand it off to an assistant, who can worry solely about who is on the ice, rather than trying to watch and coach as well.


Now the interesting part, the code: