Wednesday, May 6, 2009

wxpython with python 2.6 crashes in Windows Vista

Solution found in: http://www.python-forum.org/pythonforum/viewtopic.php?f=4&t=11331#p54621

To fix this, do the following:

* Make a copy of python.exe
* Use that copy(!) to run 'update_manifest.py' that wxPython installed in you python folder

The problem is that by default a wrong DLL version is loaded, this causes crashes in the wxWidget C++ code. In Python 2.5 and earlier the presence of the python.exe.manifest (installed by wxPython) was enough to fix this, but Python 2.6 is compiled with internal manifests, so external manifest don't work. The script will update the internal manifest so the right DLL is loaded.

You need to use a copy of python.exe to execute the script, because otherwise the program is in use and cannot be updated. After updating the manifest the program should no longer crash on mouse-events (worked for me).

Friday, May 1, 2009

MATLAB: Multiplying with a Matrix Inverse

M-Lint has detected a call to inv in a multiplication operation.
The inverse of a matrix is primarily of theoretical value, and rarely finds any use in practical computations. Never use it to solve a linear system Ax=b with x=inv(A)*b, because it is slow and inaccurate.

Suggested Action
Instead of multiplying the matrix by its inverse, use matrix right division (/) or matrix left division (\). That is:
Replace inv(A)*b with A\b
Replace b*inv(A) with b/A
Frequently, an application needs to solve a series of related linear systems Ax=b, where A does not change, but b does. In this case, use lu, chol, or qr instead of inv, depending on the matrix type.

Monday, December 22, 2008

Ubuntu: Change Default Applications in Firefox

Right clicking on a file of the same type and changing the default application via the properties does not help because GNOME default applications and system default applications are stored in two different lists.

To change the system default application (This will change the default application in Firefox):
1) sudo gedit /usr/share/applications/defaults.list
2) search and modify the line for appropriate file extension

To change the default application for GNOME:
1.a) sudo gedit /etc/gnome/defaults.list
2) search and modify the line for appropriate file extension
or
1.b) right click on file -> properties -> open with tab

Thursday, October 9, 2008

How To Compile OpenCV in Linux

How to compile C on Linux ?

  • You need to setup the PKG_CONFIG_PATH variable. For example (assuming you are using a sh-based shell, like bash or zsh):
    cd /where/you/have/the/source/code
    PKG_CONFIG_PATH=/where/you/have/installed/opencv/lib/pkgconfig:${PKG_CONFIG_PATH}
    export PKG_CONFIG_PATH
    You can check that the PKG_CONFIG_PATH is correct by doing either:
    pkg-config --cflags opencv
    pkg-config --libs opencv
    You must have something like:
    $ pkg-config --cflags opencv
    -I/where/you/have/installed/opencv/include/opencv
    $ pkg-config --libs opencv
    -L/where/you/have/installed/opencv/lib -lcxcore -lcv -lhighgui -lcvaux

How to compile and link some OpenCV based program on Linux ?

  • The best way is to use pkg-config. Just define the correct PKG_CONFIG_PATH:

    PKG_CONFIG_PATH=/where/you/have/installed/opencv/lib/pkgconfig:${PKG_CONFIG_PATH}
    export PKG_CONFIG_PATH
    And then, compile as below:
    gcc `pkg-config --cflags opencv` `pkg-config --libs opencv` -o my-opencv-prgm my-opencv-prgm.c
    Simpler way is as below:
    gcc `pkg-config --cflags --libs opencv` -o my-opencv-prgm my-opencv-prgm.c
    If those two fails, try this:
    gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ \
    -o my-opencv-prgm my-opencv-prgm.c

How to compile OpenCV with some libraries not in standard path on Linux?

  • The solution is to use the CFLAGS, CPPFLAGS and LDFLAGS environment variables at configure time. For example, if you have ffmpeg library in one of your own directories, you can do (all on one command line):

  • ./configure CFLAGS=-I/where/is/ffmpeg/include CPPFLAGS=-I/where/is/ffmpeg/include LDFLAGS=-L/where/is/ffmpeg/lib

What if I get an error about OpenCV libraries when running a program?

If an error occurs that 'a library cannot be found' during compilation on Fedora systems:
  • create a file called opencv.conf in /etc/ld.so.conf.d/ which contains the path to your opencv libraries (by default /usr/local/lib).
  • run ldconfig as root.
Or, add the location of the OpenCV libraries to your LD_LIBRARY_PATH (should work on most systems including Fedora) For additional help on FFMpeg compilation: http://freeshells.ch/~phoenix/ocv.htm

Wednesday, July 23, 2008

Shutdown Remote Desktop Windows Machine

run >> cmd >> shutdown

then follow the instructions.

Thursday, June 26, 2008

Clear disk cache linux

1) become root
2) echo 3 > /proc/sys/vm/drop_caches

Saturday, June 14, 2008

Linux Directory name with a space

Example: The directory name is: "My Stupid Directory"

Access is as: "My\ Stupid\ Directory/"

Monday, May 26, 2008

Thursday, May 22, 2008

encoding xvid in linux from a sequence of images

xvid: you must specify one or a valid combination of 'bitrate', 'pass',
'quantizer' settings

solution:
mencoder mf://*.png -ovc xvid -xvidencopts pass=1 -of avi -o
./tmp/filename.avi

or
mencoder mf://*.png -ovc xvid -xvidencopts bitrate=1600 -of avi -o
./tmp/deneme2.avi

Debian package manager manual (APT)

http://www.debian.org/doc/manuals/apt-howto/

convert multiple images from command line in linux (ubuntu)

sudo apt-get install imagemagick

convert '*.jpg' -resize 120x120 thumbnail%03d.png

more on the topic:
http://www.imagemagick.org/script/command-line-processing.php

Matlab Tips and Tricks

http://www.ee.columbia.edu/~marios/matlab/matlab_tricks.html

Pass arguments to python script

import sys

print sys.argv

Monday, May 19, 2008

Pause python

little hacky but works:

raw_input()


Thursday, May 15, 2008

Python debugger

import pdb

#this is a break point
pdb.pm()

Open text file in python

file = open("sample.txt")

while 1:
line = file.readline()
if not line:
break
pass # do something

Flush python print buffer

sys.stdout.flush()

Found here!

What this blog is

Sometimes we hit dead ends. We figure out the solution and move on. After a while we forget the fix but more often then not we find ourselves looking for the exact same solution. This blog is my notepad for these hacks. It is a blog instead of a text file because it is cool to share.