Posts

Showing posts from 2013

From 2 Numpy vectors(length=m,n) , create crossed matrix(shape=(m, n,2))

As a reminder for MYSELF, To create a matrix from two 1D vectors, like v1 = np.arange(4) #[0,1,2,3] v2 = np.arange(4) *10 #[0,10,20,30] to create crossed matrix [[[0,0],[0,10],[0,20],[0,30]], [[1,0],[1,10],[1,20],[1,30]], [[2,0],[2,10],[2,20],[2,30]], [[3,0],[3,10],[3,20],[3,30]]] I do crossed = np.dstack(( np.zeros((len(v1),len(v2)), dtype=v1.dtype) + v1[...,np.newaxis], np.zeros((len(v1),len(v2)),dtype=v2.dtype) + v2)) Is there any better way to do it? Any suggestion will be appreciated.

Calling OpenCV functions via Cython from Python 3.X.

I have managed to run OpenCV function from Python3 via Cython today, so I want to write about it. Before you start something like this, you should know you have to read at least header files of C library to write right definition in Cython,because Cython does not do that for you. I am using virtualenv, python from pythonz, and home-brewed OpenCV. Almost everything of C++ works just fine with Cython, but still, you should do some Voodoo things like for integer template argument. ctypedef void* int_parameter ctypedef int_parameter two "2" ctypedef Point_[float, two] Point2f Now, main sample Cython code is following. #===== testopencv.pyx ======== import numpy as np cimport numpy as np # for np.ndarray from libcpp.string cimport string from libc.string cimport memcpy cdef extern from "opencv2/core/core.hpp": cdef int CV_WINDOW_AUTOSIZE cdef int CV_8UC3 cdef extern from "opencv2/core/core.hpp" namespace "cv": cdef cppclass Mat: Ma

Boost.python for virtualenv (FINALLY!)

After hours of struggling, I did succeed to build boost for multiple pythons on virtualenv environments. Boost Web Site helped me very much.  As a conditions, you should know python 2.7.3 and 3.2 were installed by pythonz + virtualenv beforehand. I installed boost.python as follows. 1. Download boost from here . 2. unzip archive. > tar -xvfz boost_1_XX_X.tar.bz2 3. Exec bootstrap.sh > cd boost_1_XX_X > ./bootstrap.sh  4. Edit project-config.jam as follows # Boost.Build Configuration # Automatically generated by bootstrap.sh import option ; import feature ; # Compiler configuration. This definition will be used unless # you already have defined some toolsets in your user-config.jam # file. if ! darwin in [ feature.values ] { using darwin ; } project : default-build darwin ; # Python configuration using python : 2.7 : /PATH/TO/VIRTUALENV/PYTHON2.7 : /PATH/TO/VIRTUALENV/PYTHON2.7/HEADERS #includes : /PATH/TO/VIRTUALENV/PYTHON2.7/LIBS #libraries ;

I can't comment on my blog right now.

I don't know what's going on, but I can't write comment on my own blog. Sorry for no reply. I am checking what to do.

Is Android's FLAG_NEW_TASK named rightly???

According to an Android's document , FLAG_ACTIVITY_NEW_TASK Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent(). So, it seems FLAG_ACTIVITY_NEW is FLAG_ACTIVITY_NEW_WHEN_NOT_AVAILABLE_OTHERWISE_USE_EXISTING_ONE in truth. This name cast me a very long journey all the way around to return back to FLAG_ACTIVITY_NEW and FLAG_ACTIVITY_CLEAR_TOP combination....

Change tmux key-bind conditionally, depending on which pane are you in.

For long time since I switched from gnu screen to tmux, I have been a little wondering is there any way to change tmux behavior depending on which pane I am working. What I wanted to do is to enlarge a pane when I moved to the pane so that I can work on the bigger pane. This is a bit convenient to know which pane I am moving in and keep terminal window smaller for a laptop. I finally figured out how to do it today, I want to share it with you. (Maybe 10 more people on the earth want this info, I guess.) Key bind is like this in .tmux.conf. bind C-a if "tmux display-message -p | awk '{exit($5=0)}'" "resize-pane -D 16" \; last-pane \; resize-pane -U 8 Points are "if-shell" tmux command and -p option for tmux "display-message". As you can see, this does not work well on three or more panes, but I usually don't do that so it's OK for me. If you want it, you should add condition to second resize-pane. Any suggestion would b