Tag: Nerd

Installing OpenCV with EPD on Ubuntu 11.04

by on May.18, 2011, under Uncategorized

Quick note to self on getting OpenCV up on Linux with EPD.

When you run cmake (ccmake for the curses gui), toggle the advanced options. The python includes, binary, and lib directories are options that only show as advanced options. Change these to reflect your location for EPD. After running make, the cv.so library that python gets its functions from gets installed by default to /usr/local/lib/python2.7/site-packages/cv.so. Copy it instead to EPD_INSTALL_DIR/lib/python2.7/site-packages. You should be good to go, now.

Also, one other problem:
Ubuntu 11.04 has pulled the old switcheroo on library locations. If you’ve installed all the dev versions of the necessary libraries (libjpeg, libpng, libtiff, libzip were my problem libraries), you also need to create symlinks from their new locations to the locations that OpenCV’s make/CMake is expecting to find them:

ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
ln -s /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/libpng.so
ln -s /usr/lib/x86_64-linux-gnu/libtiff.so.4 /usr/lib/libtiff.so
ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/libz.so

This hint courtesy of:
http://www.nigeldunn.com/2011/05/14/ubuntu-11-04-libjpeg-so-libpng-so-php-installation-issues/

Leave a Comment :, , , , more...

Renaming Visual Studio 2003 projects

by on Apr.13, 2011, under Nerd

Edit, Nov 19, 2011

NOTE: this post is out of date. Instead, please see the project here:
DM plugin – serial communication

This project uses relative paths everywhere, and sets output filenames dynamically based on the project name. To use it, extract/sync the github repository to an installation of the DMSDK, then rename the project in Visual Studio. You should be able to safely rename the project folder without breaking anything.

======================= Original post below ===================================

Yes, VS 2003 is out of date. I use it to compile C++ extension plugins for Gatan Digital Micrograph (DM), which we use to control our microscopes and acquire/process data. The SDK for DM is designed for Visual Studio 2003 (or older).

Part of the problem of doing something that very few others do is that the documentation is usually poor. This is very much the case with the SDK.

Here was my problem:

  • I don’t know how to create a new project and have it compile. The SDK is sufficiently complicated and different from any standard Visual Studio project that it is difficult to take this path.
  • I don’t know how to rename my VS 2003 project files without breaking the project. Thus, I am unwilling to distribute the source code to my project, since it is named something completely unrelated.

Here’s my solution:

  • In Windows Explorer:
    1. Rename the project folder in the filesystem.
    2. Rename the .sln and .rc files in the project folder. DO NOT rename the .vcproj file.
  • In VS2003:
    1. Open the project by picking the .sln file to open.
    2. Rename the project in the solution explorer (right click, and select rename)
    3. Select the project in the solution explorer, and then click the File menu. Select Save as… and enter the new filename for your .vcproj file. You can now delete the old .vcproj file from the folder.
    4. For old source files to be excluded, right click them in the solution explorer, and click remove.
    5. For new files to be included, right click on the project or folder in the solution explorer, and select Add… -> Add existing item…
    6. In the project properties (right click the project, and select properties):
      1. Under C/C++, pick the Precompiled Header options, and rename the Precompiled header file appropriately (not entirely necessary, this is a cosmetic change since this file gets (re)generated automatically when necessary)
      2. Under Linker, in the General options, change the Output File.
      3. Under Linker, Debugging: update the “Generate Program Database File” option
      4. Under Linker, Advanced: update the “Import Library” option

Now you should no longer have any files popping up with the old name.

Good luck with your DM plugins and renamed VS 2003 projects!

Leave a Comment :, , more...

Windows command prompt here

by on Feb.28, 2011, under Uncategorized

Learned a really handy trick today. To open a windows command prompt from Windows Explorer, you can click in the address bar (the cookie crumb trail in Windows 7). It will turn into your full path. Delete the whole path, and type cmd, then hit enter.

Leave a Comment : more...

Linux wins again!

by on Jan.25, 2011, under Uncategorized

I’ve been cursing the wireless card in my computer since I pieced it together last week. It’s an Asus PCE-N13. It didn’t require any extra driver installation under either Windows 7 x64 or Ubuntu 10.10. However, the signal was very poor in Windows, with constant drop-outs, and it would not detect any networks at all in Ubuntu.

I haven’t found a solution to Windows problems yet, but I blacklisted a few modules in Ubuntu, namely by adding these lines in /etc/modprobe.d/blacklist.conf:
blacklist rt2800pci
blacklist rt2800usb
blacklist rt2x00lib
blacklist rt2x00pci
blacklist rt2x00usb

Now Ubuntu is connecting like a champ. Blazing fast, and reliable. It seems to be using the rt 2860sta driver instead of the blacklisted ones now.

I originally found this information on the Ubuntu forums: http://www.uluga.ubuntuforums.org/showthread.php?t=1579053&page=2

Leave a Comment : more...

by on Apr.12, 2010, under Uncategorized

“It is the faith of all science that an unlimited number of phenomena can be comprehended in terms of a limited number of concepts or ideal constructs. Without this faith no science could ever have any motivation.”

L.L. Thurstone, Modern Factor Analysis

Leave a Comment : more...

Dissertation writing tips: Latex and Mendeley

by on Jan.18, 2010, under Nerd, Uncategorized

Some odd notes of potential usefulness as I stumble through dissertation writing:

  • Proper figure numbering is accomplished by including the \label{} command inside the \caption{caption} command. Otherwise, it catches the section number…
  • Mendeley is great for managing references. Set the web importer up as a bookmark in the bookmark toolbar. It can grab references from Google Scholar, Google books, and many others. I find that the direct grabs from a Google Scholar search are incomplete – where possible click the link through to the page with the abstract, and import the article from there.
  • Store your articles with Mendeley’s web storage to keep them in sync across multiple computers. To start storing them, right click your “All Documents” collection, then “Edit settings” (Why isn’t there any reference to this in Mendeley’s program settings? I had a hell of a time finding this.)
  • \ref and \cite are very different Latex commands. If a bibtex reference refuses to show up, you probably tried to cite it using \ref, rather than \cite. \ref is for references defined by \label.

And… my theme here apparently has a problem showing bulleted and numbered lists…

Leave a Comment :, , more...

OS X 10.6 problems & fix

by on Dec.16, 2009, under Uncategorized

Oh boy, was I seething at Apple after upgrading to 10.6. It seemed like just about everything broke. All of my Python development stuff went to hell in a handbasket (a stylish, well-designed handbasket). My 600$ (educational) copy of the Adobe CS3 Design pack would not even install. To boot, X11 did not work, so I couldn’t even use trusty old NXclient to remote desktop on my linux box.

I’m not sure why, but I didn’t bother searching for anyone with similar problems at the time. After going through the trouble to revert to 10.5, I did that search, and found all kinds of exactly similar problems, mostly caused by cruft from the old system. After a fresh OS X 10.6 install, things are in much better shape. Yes, there are other ways to clean up the cruft, but fresh installs feel so nice. CS3 still won’t install, but I can live with Inkscape and the GIMP.

Long story short: OS X is not the bulletproof OS that it is often advertised as, but it’s also not as bad as I thought.

Oh, one quirk:
Everyone mentions how much space 10.6 frees up on their hard drive. That’s nonsense. It may use a tiny bit less space, but the real “increase” in hard disk space comes because they switched to calling kilobytes 1000 bytes, rather than 1024 bytes (and MB are 1000 KB, and so forth). Because it divides the total number of bytes by an accordingly smaller number, you end up with a “bigger” hard drive. This has long been what the hard drive manufacturers do, but it’s awfully shady and very arbitrary for Apple to make that switch now.

Leave a Comment : more...

OpenCV image registration

by on Oct.13, 2009, under Uncategorized

This is more a note to self than anything else, but if you find it useful, hooray!

I’m trying to register images for school. There’s a neat trick to get rotation & scale roughly aligned, without doing any kind of brute forcing (which is really important, because my images can be any angle offset from one another). You take the log-polar transform of each image, and then cross-correlate the two transformed images. The distance from the center to the cross correlation maximum along the Y axis tells you the rotation, and the same on the X axis tells you the scale (on a logarithmic scale). The end result is that you can avoid the local alignment maxima associated with brute forcing, and save a whole lot of time in the process.

However, it doesn’t work perfectly for me yet. Here’s a few steps I’ve taken to improve it:

1. Pad the image that you’re going to match the template on.
Python with ctypes_opencv:

pad_img=ocv.cvCreateImage(ocv.cvSize(cropWidth*3,cropHeight*3),
expIPLimg.depth,expIPLimg.nChannels)
offset=ocv.cvPoint(cropWidth,cropHeight)
ocv.cvCopyMakeBorder(expLP, pad_img, offset,
ocv.IPL_BORDER_CONSTANT, ocv.cvAvg(expLP))

2. Do not cross-correlate the entire template to match. Instead, match only the central strip. There’s plenty of good stuff to match there, and you avoid the correlation penalties of having your template overlap with the padding. If you don’t do this, then the scale correction possible will be limited.

resultWidth = pad_img.width – refLP.width/2 + 1
resultHeight = pad_img.height – refLP.height + 1
result = ocv.cvCreateMat(resultHeight,resultWidth,ocv.CV_32F)
ocv.cvSetImageROI(refLP,ocv.cvRect(refLP.width/4,
0, refLP.width/2, refLP.height))
ocv.cvMatchTemplate(pad_img,refLP,result,ocv.CV_TM_CCOEFF_NORMED)

2 Comments : more...

Fixed width string formatting in python

by on Feb.25, 2009, under Nerd, Uncategorized

I wanted to make a nice, pretty text file from some log info, but python didn’t want to cooperate with string formatting.

I was trying something like this:
f=open(‘file’,'w’)
f.write(‘%-10s’ %string)

At the interactive prompt, the equivalent print command would give the desired result.

I got it to work by replacing f.write() with
print >> f, mystring.ljust(10)

This code has the same net result of printing to the file, but it actually does the spacing properly.

This thread gave me the hint I needed, though it looks like the poor guy never resolved his issue – he should have tried the print suggestion.

http://bytes.com/groups/python/25205-using-string-ljust-try-hold-fixed-width#links

1 Comment : more...