Javascript is only the language that programmers use without learning it. In other words, the javascript language model is perfectly easy-to-use and reasonable to copy-and-paste. However as Douglas mentioned in this lecture, javascript also has fancy nice features derived from scheme & lisp. The closures help us hide unnecessary inside and disclose necessary interface between objects and functions. See the singleton example on the presentation.

During this winter, I am going to learn javascript from the syntax again. I love computer programming laguages itself, not just javascript alone. These are the lists of languages that I have to learn seriously D/Perl/Haskel/Ruby/Java/C#/.NET(CLR). Frankly, I am using Python mostly for my works and research – I don’t have any chance to be familiar with other languages even I read a couple of books on Haskel, Java and Ruby. I forgot the essence of them.

These are my native programming languages – gas, c, c++, python, lisp.

This is a video presented 2 years ago. They were talking about Meshup Problem of web site such as portal, ads, gears, and plugins. We still have same problems – for example cross site script and cross site forgery. See the recent papers trying to solve the mashup problem in browsers – Securing Frame Communication in Browsers.What I am doing is to modify chrome, firefox and apache to provide secure sandbox models on each components by keeping principle of least privilege.

One of the holy wars among developers .. tab vs spaces ..

In Linux, most of old codes are using tabs ..

but I like 4 spaces instead of tab because everybody can see my codes exactly as I see.

:)

However, we sometime have to be patient on other’s codes ..

1
2
3
4
(if (save-excursion
(beginning-of-buffer)
(search-forward "\t" (min 1000 (point-max)) t))
(setq tab-width 8))

For Xen developers, this book is real definite guide, but to understand what is hypervisor and how it works, this is not the solution. However, to understand how precisely they implemented Xen and their perspective as providers, this book is pretty fun :)

  • Hey, I can’t use my laptop just because no wireless network – my own machine!
  • Hey, to connect the network, I have to get certificate first, how can I do that?
  • Hey, don’t regard me as stupid
  • Did you catch that they are not using a wireless device to flap the next slide?
  • Without TPM/TCM, how can they check signatures of ‘firmware’, lowest component of Chrome OS?
  • Yep, as you saw, they are relying on Flash Player (external module) unreliable unless Google monopolize everything!
  • They made javascript allow to access hardware, how can they manage capabilities, which not mostly ignored in Linux?
  • Fast? I feel slow – Need native execution framework like native client
  • If any extension is allowed, whole system will be vulnerable ever
  • All my information/data is concentrated only on my ‘password’
  • If you password is disclosed, any attacker can access your data in ‘any’ google machine under Chrome OS
  • We cannot develop Chrome OS application on Chrome OS, see this article http://www.paulgraham.com/apple.html
  • I have to compile/install and read the codes next week

Concurrency features & Fast compilation of Go Programming Language are pretty exciting, but I am little confused of language semantics and syntax. I have to keep my eyes on.

Why system language? – there is run time support.

Why we feel compilation is fast? – stacking objs files could make snow ball effects on little modification

New language? we can support easy-to-use concurrency features as library

Many languages, hard to cover them all. no time to spend on them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#define D "#define"
#define P "("
#define E ")"
#define X "\\"
#define Q "\""
#define S " "
#define N "\n"
#define V "#"
#define SS "S"
#define SX "X"
#define SQ "Q"
#define SF "F"
#define SD "D"
#define Sn "n"
#define SN "N"
#define M "int main(){"
#define C "}"
#define H "    printf(F(D) F(P) F(E) D S SX S Q X X Q N D S SQ S Q X Q Q N F(S) D S SN S Q X Sn Q N F(V) F(SS) F(SX) F(SQ) F(SF) F(SD) F(Sn) F(SN) F(M) F(C) F(H) F(R) D S SF P SX E S SD S SS S V SX S SS S SQ S SX S SQ S SN N N M N H N R N C);"
#define R "    return 0;"
#define F(X) D S #X S Q X Q N

int main(){
printf(F(D) F(P) F(E) D S SX S Q X X Q N D S SQ S Q X Q Q N F(S) D S SN S Q X Sn Q N F(V) F(SS) F(SX) F(SQ) F(SF) F(SD) F(Sn) F(SN) F(M) F(C) F(H) F(R) D S SF P SX E S SD S SS S V SX S SS S SQ S SX S SQ S SN N N M N H N R N C);
return 0;
}

gcc self.c -o self ; ./self > replica.c ; diff self.c replica.c

Stimulate your brain, too!

ps. not pretty code scheme, I have to check others

Dogs bark.  Ducks quack.  Chickens can’t fly very well.  What else do we
need to know?

Take a break from all that hard research and come to girl scout benefits!

….

I got an email from GSB, fun! but I need to know something to survive :)

Finally I read this book, visualizing data. Frankly, I expected new approaches, how to visualize data, so attractive. However, this book is inclined to the introduction to the Processing Language and its internal implementation and design. I have a toolkit to visualize data, matlibplot written with python. This matlibplot is beautilful because I can embed it within other GUI framework such as gtk, and lovely wxwidget and wxpython. The Processing Language is written at CMU for students, professionals, and artists. Looks promising but not align with me. That is because it is not extensible at all. The Processing Language is just backend and hard to extend it as real processing engine.

Introduction

The OpenCV is one of the greates and widely using image library for all developers and students. However, I am not a OpenCC and Graphics guy, but I choose OpenCV for Video Recording purpose. Since I mostly live and develop within Ubuntu, I tried writing and testing a little python-opencv program, but not working. It is mainly because the problem of new ffmpeg in ubuntu 9.04 Jaunty – see, https://bugs.launchpad.net/ubuntu/+source/opencv/+bug/311188. While searching the Internet, I found an article to use video streaming of opencv(here, http://gijs.pythonic.nl/blog/2009/may/3/getting-video-io-working-opencv-and-ubuntu-jaunty-/). I tired because I don’t want to reinvent the wheel of course, but not working like many comments on ‘cvCreateVideoWriter‘ function.

Prepare to compile

Prepare to build

1
2
sudo apt-get build-dep python-opencv
sudo apt-get install libswscale-dev swig

Prepare to configure

Link avcodec.h, avformat.h, avio.h, avutil.h and swscale.h in the /usr/include/ffmpeg (you have to create) like below.

1
2
3
4
5
6
ls /usr/include/ffmpeg
avcodec.h -> ../libavcodec/avcodec.h
avformat.h -> ../libavformat/avformat.h
avio.h -> ../libavformat/avio.h
avutil.h -> ../libavutil/avutil.h
swscale.h -> ../libswscale/swscale.h

Checkout OpenCV

1
svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/tags/latest_tested_snapshot

Configure & Make

1
2
cd latest_tested_snapshot/opencv
./configure --enable-shared --enable-swscale --enable-gpl --with-swig
  • –enabled-shared : as shared library
  • –enable-swscale : alternative work around for ffmpeg
  • –enable-gpl : opensource library
  • –with-swig : regenerate swig interfaces
...
    Video I/O ---------------------
    Use QuickTime / Mac OS X: no
    Use xine:                 no
    Use gstreamer:            no
    Use ffmpeg:               yes
    Use dc1394 & raw1394:     no
    Use v4l:                  yes
    Use v4l2:                 yes
    Use unicap:               no

Wrappers for other languages ========================

    SWIG                      /usr/bin/swig -c++
    Python                    yes
    Octave                    no
...

The highlighted configuration items are important, ffmpeg / swig / python. If everything is find, do make. The interface files in the checkout directory are not properly generated, so you have to generate yourself.

1
2
make
sudo make install

Test and Correct OpenCV Python files

1
2
3
4
5
6
7
8
9
10
11
$ cd /usr/local/lib/python2.6/site-packages/opencv
$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for ...
>>> import cv.py
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cv.py", line 8473, in <module>
    CV_SEQ_CONTOUR=CV_SEQ_POLYGON
NameError: name 'CV_SEQ_POLYGON' is not defined

Open cv.py and Edit

1
CV_SEQ_CONTOUR=CV_SEQ_POLYGON

(line 8473) to

1
CV_SEQ_CONTOUR=CV_SEQ_POLYGON_TREE

Everything is done.

Example of OpenCV and PyGame

Displaying two Video Cameras as one concatenated video and record it to a file.

screenshot_0551

screenshot_056

To make my program independent, I just copied the opencv python binding to the local directory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sys
import pygame
import Image
import opencv

from PIL import Image
from pygame.locals import *

from opencv import highgui
from opencv import cv

def get_image( camera1, camera2 ) :
    im1 = highgui.cvQueryFrame( camera1 )
    im2 = highgui.cvQueryFrame( camera2 )
   
    pil1 = opencv.adaptors.Ipl2PIL( im1 )
    pil2 = opencv.adaptors.Ipl2PIL( im2 )

    img = Image.new( "RGB", (pil1.size[0] + pil2.size[0], pil1.size[1]) )
   
    img.paste( pil1, (0,0,pil1.size[0],pil1.size[1]) )
    img.paste( pil2, (pil1.size[0],0,pil1.size[0]+pil2.size[0], pil2.size[1] ) )

    return img

def CV_FOURCC( c1, c2, c3, c4 ) :
    return (((ord(c1))&255)             \
                + (((ord(c2))&255)<<8)  \
                + (((ord(c3))&255)<<16) \
                + (((ord(c4))&255)<<24))

if __name__ == "__main__" :

    camera1 = highgui.cvCreateCameraCapture( 0 )
    camera2 = highgui.cvCreateCameraCapture( 1 )

    ( width, height ) = ( 640, 480 )
    fps = 30.0
    pygame.init()
    window = pygame.display.set_mode( ( width * 2, height ) )
    pygame.display.set_caption( "WebCam Demo" )
    screen = pygame.display.get_surface()

    writer = highgui.cvCreateVideoWriter( "captured.avi",
                                          CV_FOURCC('M','J','P','G'),
                                          fps,  
                                          cv.cvSize(width * 2, height) )

    if not writer :
        print "Error on writer"
        exit(1)

    on_exit = False

    while not on_exit :
        events = pygame.event.get()
        for event in events:
            if event.type == QUIT or event.type == KEYDOWN:
                on_exit = True

        im = get_image( camera1, camera2 )

        highgui.cvWriteFrame( writer, opencv.adaptors.PIL2Ipl(im) )
       
        pg_img = pygame.image.frombuffer( im.tostring(), im.size, im.mode )
       
        screen.blit( pg_img, (0,0) )
        pygame.display.flip()
        pygame.time.delay( int( 1000 * 1.0 / fps ) )
1
2
3
python webcam.py
Output #0, avi, to 'captured.avi':
Stream #0.0: Video: mjpeg, yuvj420p, 1280x480, q=2-31, 78643 kb/s, 90k tbn, 30 tbc

Reference

  1. https://bugs.launchpad.net/ubuntu/+source/opencv/+bug/311188\
  2. http://ubuntuforums.org/showthread.php?p=7315433
  3. http://code.google.com/p/ctypes-opencv/source/checkout
  4. http://gijs.pythonic.nl/blog/2009/may/3/getting-video-io-working-opencv-and-ubuntu-jaunty-/
  5. http://www.pythonware.com/products/pil/

Disclamer

I copied all of ideas from the Internet and just do it myself for my purpose. However, if you want, feel free to use above example under GPL v.2. Thanks.