Head.SmackOnTable();

Contains Nuts.

Archive for May, 2009

My dev setup

with 5 comments

Well iv seen hundreds of posts such as “This is my Firefox setup” and “This is my Visual Studio Setup”, but not many that is, well basically, everything…

First off, this is my desk. Its a cheapo Ikea corner table, that fits. Iv got a bog standard mesh chair, from Ebuyer, for about 60 quid.

My hardware / desk setup:

  • Custom built Monster:
    • Quad Core Processors
    • 8gb of the fastest DDR2 ram that was out
    • Dual 500gb HDDs
    • Dual DVD writers
    • 2 monitors – one 20″ widescreen, one 19″ bog stanard, both Iiyama’s (I know i have 3 on my desk, the 3rd one is hooked up to a temp pc)
  • Sennheiser HD 465 Headphones – very comfortable, fairly cheap, I wear them for hours a day with no problems
  • A small “localised” lamp from Homebase, useful for looking at small things
  • MS Natural Keyboard
  • Microsoft Laser Gaming Mouse 6000 – Its a lightweight mouse, the last thing you want is a big heavy mouse to move around all day.
  • A speaker / subwoofer setup, from Ebuyer, for about 10 quid – for when headphones arnt good enough (probably not recommended for offices!)
  • At the bottom of the picture is a fan, for when I get hot, yeah baby! ;)
  • Im not sure why my laptop was sitting on my desk…ignore that.

My “misc” software setup:

  • Running Vista  SP1 – im tempted to run Windows 7, but not anytime soon, im just getting used to Vista!
    • UAC is disabled on Vista – its the FIRST thing i do when installing vista on a box!
    • IIS7 and management tools installed.
  • Hostsman – easy editing of your hosts file for testing
  • Winamp – for music! You cant code without music!
  • Windows Clippings – easier to use than other screen grabbing software, very lightweight, very very good, deffo worth the $18! Has useful features like timers and ability to send to clipboard etc…
  • MSN Messenger / Skype – I know some companies dont like it when their staff play around on IM, so dont abuse it – its saved my skin a few times when iv had trouble, and its less intrusive in the office than annoying someone
  • WinSCP – freeware FTP / SFTP/ FTP over SSH client – covers pretty much any server you need to connect to, its free, and it just beats all other FTP clients hands down.
  • Ultramon – you get a 2nd taskbar for your 2nd monitor, so basically only the stuff that is running on that monitor is on the taskbar.
  • Microsoft Outlook – I have outlook running for my email – its easy to use, very straight forward, and quite cool with exchange.
  • Daemon Tools Lite – when you have to mount ISOs without burning them, useful for .iso files downloaded from microsoft / off network shares.
  • Microsoft Virtual PC 2004 SP1 – free software from MS, basically allows you to run virtual pc’s – useful for running XP off a virtual machine (Crappy versions of IE, anyone?) – although I had problems installing debian on it, so im looking into running VirtualBox
  • Firefox – better than IE by MILES. Have loads of plugins, such as Web Dev toolbar, firebug, greasemonkey, firephp, Fission (cool loading bar thing), IE Tab, Its All Text (You get a cool little “Edit” button on text area’s that load it up in notepad), ShowIP (Shows ip address of server), AdBlock (blocks 99.99% of crappy ads), ColorZilla (picks colours out from page), Download Statusbar, Extended Statusbar (tells you pagesize, how long it took to load, etc).
  • Opera – because someone will complain that it dosent work in this browser
  • FeedDemon / Newsgator – Free software that sync’s with their free website, so you can still check your favourite feeds away from home. By far the cleanest, easiest to use, and best RSS reader there is.
  • Hamachi – Free VPN software that works behind firewalls, very very useful, esp when you have less tech savvy friends.

My dev setup:

  • Visual Studio 2008 Pro – Pro because you need at least that for integrated unit tests and Pex to run.
  • Codesmith Generator, with my own custom version of Nettiers code generator – WHY on earth would you want to write CRUD (Create, Read, Update, Delete) for your DB/objects over and over? Point this baby at it, and go baby go!
  • Resharper – Solution wide error highlighting BEFORE you hit the big compile button. Instant solution for alot of errors. Advanced intellisense. Advanced unit testing tools. Code clean up, inline code generation. Even does cool stuff like close your speach marks and brackets for you!
  • A White text on dark background colour theme like the image below – the last thing you want to do is look at retina scortching white screen for hours on end, it will do your eyes in, it really will.
    windowclipping-214
  • I tend to have Microsoft SQL Server installed on a virtual PC, so I can mimic the server environment – you can use the Microsoft Loopback Adapter to create your own private network – a hint, the 1.* ip address network (same for 2. all the way upto 9) is non routable, so feel free to use them for your virtual machines – i.e. my vps start off at 1.1.1.2 etc)
  • Not sure if this should go in Misc or not, but NotePad++ – iv replaced notepad.exe in window with this, and it works ACE!

Im sure I have forgotten something, so when I remember, ill add to this post. If you have any great ideas, lets hear them!

Written by Monty

May 21st, 2009 at 2:10 am

Posted in Misc

Tagged with

LAB: Image Detection, Part 3

without comments

After writing some comparison code, we have the following output, thanks to log4net (I love log4net):

output-3

Source


Target

.

X:79 Y:156 W:17 H:23 X:73 Y:149 W:17 H:23

.

X:337 Y:176 W:27 H:50 X:331 Y:169 W:27 H:49

.

X:158 Y:249 W:32 H:31 X:152 Y:242 W:32 H:32

.

X:446 Y:286 W:28 H:32 X:440 Y:279 W:27 H:32

.

X:398 Y:339 W:18 H:26 X:392 Y:334 W:16 H:24

.

X:244 Y:349 W:47 H:52 X:238 Y:342 W:47 H:52

.

X:38 Y:374 W:16 H:15 X:31 Y:366 W:17 H:16

.

X:34 Y:388 W:16 H:17 X:148 Y:423 W:27 H:24

.

X:154 Y:430 W:27 H:24 X:459 Y:435 W:24 H:22

.

X:465 Y:442 W:25 H:22 X:119 Y:450 W:30 H:46

.

X:126 Y:457 W:29 H:46 X:221 Y:465 W:17 H:19

.

X:227 Y:472 W:17 H:19 X:250 Y:594 W:17 H:18

.

X:256 Y:601 W:17 H:18



Comparison
S[X: 79, Y: 156, Width: 17, Height: 23] matched to T[X: 73, Y: 149, Width: 17, Height: 23]
S[X: 158, Y: 249, Width: 32, Height: 31] matched to T[X: 152, Y: 242, Width: 32, Height: 32]
S[X: 398, Y: 339, Width: 18, Height: 26] matched to T[X: 392, Y: 334, Width: 16, Height: 24]
S[X: 38, Y: 374, Width: 16, Height: 15] matched to T[X: 31, Y: 366, Width: 17, Height: 16]
S[X: 154, Y: 430, Width: 27, Height: 24] matched to T[X: 392, Y: 334, Width: 16, Height: 24]
S[X: 126, Y: 457, Width: 29, Height: 46] matched to T[X: 31, Y: 366, Width: 17, Height: 16]
S[X: 256, Y: 601, Width: 17, Height: 18] matched to T[X: 31, Y: 366, Width: 17, Height: 16]
Non matched
S[X: 34, Y: 388, Width: 16, Height: 17]
S[X: 154, Y: 430, Width: 27, Height: 24]
S[X: 465, Y: 442, Width: 25, Height: 22]
S[X: 126, Y: 457, Width: 29, Height: 46]
S[X: 227, Y: 472, Width: 17, Height: 19]
S[X: 256, Y: 601, Width: 17, Height: 18]
T[X: 148, Y: 423, Width: 27, Height: 24]
T[X: 459, Y: 435, Width: 24, Height: 22]
T[X: 119, Y: 450, Width: 30, Height: 46]
T[X: 221, Y: 465, Width: 17, Height: 19]
T[X: 250, Y: 594, Width: 17, Height: 18]

I know its not perfect, I know its only matching about 50% of the blobs, but im working on it. I have a plan up my sleeve for this :)

Written by Monty

May 8th, 2009 at 1:19 am

Posted in .NET, R&D Lab

Tagged with , , ,

var – Considered harmful

without comments

There seems to be a new phenomenon in the c#.net 3.5 world, where people are using the “var” keyword, because, well I’m guessing they are lazy. Take this example, what is MORE READABLE:

var sourceRect = new ComparisonRectangleContainer();

OR

ComparisonRectangleContainer sourceRect = new ComparisonRectangleContainer();

Now, I know that will be straight forward, you can see what the new type is, it will be a ComparisonRectangleContainer, but what happens when you use var when getting a response from a method, like the following:

var parallelCombiner = FirstPass();

Now, what does FirstPass return? Is it an IList<String>? No, I have to mouseover to find out:

image

Ok, so it turns out it returns an ImageParallelCombiner, the first bit of code does not make it clear.

You should always write code for HUMANS, not the compiler

The following is PERFECTLY valid c#.net code, but is it good code?

var @this = new @class();

@base.@stackalloc(delegate(@if @event)

{

if (!@return.@bool(@event)) return;

@is.@const(“S[" +@event + "] matched T[" + @return.@override(@event) + "]“ );

@this.@implicit(@event);

});

Note – you can prefix variable names with @ if you want to use a keyword – i.e. @class is a valid variable name, so is _ (underscore) – perfect if you want to make things as hard as possible for people to read it, like the “var” keyword.

Written by Monty

May 8th, 2009 at 12:58 am

Posted in .NET, Spleen Vent

LAB: Image Detection, Part 2

without comments

Warning – this post will be heavy on images, so if you are on a low bandwidth connection, well sucks to be you then.

With a few minor improvements to the code, here we have the Source image:

image

Here is the target image’s blobs:

image

As you can see, it has found both blobs, and here is the raw output for the blob data:

image image

They are very similar, only a few pixels out! Now to compare the images somehow…

Written by Monty

May 4th, 2009 at 1:25 pm

Posted in .NET, R&D Lab

Tagged with ,

Code Snippets – Text on images

without comments

Two code snippets for you:

private void drawTextWithBackground (string Text, Font font, Graphics grpaphics, Brush backgroundBrush, Brush foregroundBrush, int x, int y)

{

SizeF size = grpaphics.MeasureString(Text, font);

grpaphics.FillRectangle(backgroundBrush, x,y,size.Width, size.Height);

grpaphics.DrawString(Text,font,foregroundBrush,x+1,y+1);

}

private void drawTextAtBottom (String Text, Font font, Graphics graphics, Image sourceImage, Brush backgroundBrush, Brush foregroundBrush)

{

SizeF size = graphics.MeasureString(Text, font);

int y = (int) (sourceImage.Height – size.Height);

drawTextWithBackground(Text,font,graphics,backgroundBrush,foregroundBrush,1,y);

}

Does exactly what it says on the tin!

Written by Monty

May 4th, 2009 at 1:13 pm

Posted in .NET, Code Snippet, R&D Lab

Tagged with ,

LAB: Image Detection, Part 1

without comments

Every now and then, I get a crazy idea, to try something rather hard in .net – maybe hard isnt the right word for it, but something that hasn’t really been attempted before, or if it has, nothing public about it. So the idea I have is for some form of image detection, to say that Image X is x % similar to Image Y. I prefer to use the terms Source and Target, but it doesn’t really matter.

The source and the target images are here. That’s a photo I took a few weeks ago, if you do decide to steal it, please put a message on there that points back to me ;) Anyway, the target image is 14×15 pixels smaller – that’s a whopping 210 pixels different! It shouldn’t be too hard to match up the two images, or should it?

Histograms

My first attempt was with Histograms. I grabbed some open source (unsafe!) code that generates an array of int[] and lists the histogram values, so I shoved both images through that, and got it to output the Source’s histogram value, the Target’s histogram value, the difference between them both, and the percentage of how similar it is, like so: (The first number is the key# of the int in the array, just because)

image

Right at the bottom, I had an average of all the percentages, to see how “similar” the image is. I was expecting the percentage to be fairly high, since there is only a few hundred pixels difference, and I didn’t change any of the levels or colours when I cut the images out of each other, but it told me there was a 87.7% similarity! That was very shockingly low. If you see something wrong with my maths from the code below, please let me know:

public HistogramCompareResults(int key, int source, int target)

{

this.key = key;

this.source = source;

this.target = target;

difference = source – target;

if (difference < 0)

{

difference = difference*-1;

}

if (source != 0 && target !=0)

{

if (source > target)

{

percentage = (double)target / (double)source;

}

else

{

percentage = (double)source / (double)target;

}

percentage = percentage*100;

}

}

Image Processing

My next port of call was basically image processing, like what I did with my ANPR project that I created – basically filtering stuff out and building a “thumbprint” of the image, that hopefully will withstand being resized and stuff like that. Using image filters, flattening images and looking for large “blobs” of images, sofar I have come up with this:

image

That is the current “thumbprint” for the red channel, on the source image.

Written by Monty

May 4th, 2009 at 12:30 am

Posted in .NET, Code Snippet, R&D Lab

Tagged with , ,