Posts

pip3 fails to compile C module(like Pillow, readline etc) on Yosemite

After upgrading OSX to Yosemite, I found pip3 was not working on homebrewed python3. There seems to be many blogs about this problems but I should do some try-and-errors to fix. Here is what I did in order.  1. install Command Line Tools for 10.10, downloaded from Apple Developer(https://developer.apple.com/downloads/index.action) .  2. reinstall gcc brew reinstall gcc  3. reinstall python3 brew reinstall python3  4. do pip pip3 install pillow I am not sure this is the best way, but it worked for me at least. Hope this helps somebody.

Swift seems nice, but cannot write simple function such as converting array to UnsafePointer

I'm writing an iOS accelerated framework application with Swift and it's frequently necessary to convert Swift array to unsafe pointer. However the conversion function I wrote cannot be compiled. Does anybody know what's wrong with this function? func aryToUnsafePointer<T>(ary:T[]) -> UnsafePointer<T> { return UnsafePointer<T>((&ary as CMutablePointer<T>).value) } The error is 'T[]' is not a subtype of '@lvalue $T1' problem solved thanks to Justin It is not allowed to take "&" of argument directly, so changing function like this will work. func aryToUnsafePointer<T>(ary:T[]) -> UnsafePointer<T> { var a = ary return UnsafePointer<T>((&a as CMutablePointer<T>).value) } Now I understand the reason, but it seems a bit odd to me, though.

Why "CoreDragMessageHandler : Cannot track drag receiver. No pasteboard name."

I am trying to drag&drop file on a PySide application, however, An error "CoreDragMessageHandler : Cannot track drag receiver. No pasteboard name." keeps happening. It turns out, the reason is starting application from tmux. We should avoid starting application from tmux when trying to support a drag&drop.

Roating CGImageRef on iOS.

For reminder to myself, rotate image on center. CGImageRef imageref = [self imageFromSampleBuffer:sampleBuffer]; // or any other CGImageRef source. int w = CGImageGetWidth(imageref); int h = CGImageGetHeight(imageref); CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageref); CGContextRef bitmap = CGBitmapContextCreate(NULL, w, h, CGImageGetBitsPerComponent(imageref), CGImageGetBytesPerRow(imageref), colorSpaceInfo, CGImageGetBitmapInfo(imageref)); CGContextTranslateCTM(bitmap, w/2, h/2); CGContextRotateCTM(bitmap, M_PI_4); CGContextTranslateCTM(bitmap, -w/2, -h/2; CGContextDrawImage(bitmap, CGRectMake(0, 0, w, h), imageref); CGImageRelease(imageref); imageref = CGBitmapContextCreateImage(bitmap); CGContextRelease(bitmap); return imagereff;

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 #libr...