Saturday, January 4, 2014

FingKinector - Interacting with the Kinect Motor



The pivot which connects the Kinect sensor to its base is motorized. This post is about an app called 'FingKinector', which is developed to utilize that motorized pivot without having to rotate the Kinect sensor manually. This is tested only on the Kinect sensor for XBOX 360 and developed for Windows 7.

"K.I.S.S. = Keep It Stupid, Simple"

Image 1: Kinect Sensor for XBOX 360, equipped with a wide-angle lens.

To be able to control the Kinect sensor from a PC, you will need an AC-adapter for your Kinect. It costs around € 8.00 on the Amazon. It has 2 outputs: the orange plug connector is used to supply the Kinect with 12 V at 1 A, whereas the second output is a regular USB connector [1].

If your Kinect is connected to your PC for the first time, by default Windows will attempt to automatically download and install the driver for that Kinect, which comes from PrimeSense. PrimeSense is the developer of the range camera in the Kinect sensor and it is an Israeli 3D sensing technology. As of this time - PrimeSense has become a subsidiary of Apple Inc [2].

At the bottom of this post, the writer puts a link for you to download FingKinector.

FingKinector works in 2 options:
  1. Single run
  2. Sequential run
The following image shows the first mode (single run). It is known from [3] that the motor is allowed to be tilted to an angle between -27° and 27°.

Image 2: Single Run mode on FingKinector

The second mode, as seen in Image 3 below - the sequential run, uses a factor to divide the range [-27°,27°] up to 10 sectors. By default this mode will first turn the Kinect to the position of 0°, then starts the sequential movement from either top (at 27°) or bottom (at -27°).

Image 3: Sequential mode on FingKinector

The writer also took a liberty to record an amateur video to demonstrate the sequential mode. The Kinect here is seen with an extra hardware called Kinect Zoom Wide-Angle Lens by Nyko [4]. Its cost is around € 14.00.



Sources:

REMINDER / WARNING:
  1. For Windows only. (Linux version will be made available in the next development)
  2. The writer is NOT liable for any damage.
  3. Use at your own risk.
Have fun!

Friday, September 13, 2013

A Stupid and Simple App: FingCryptor



Julius Caesar used to apply a simple trick in sending his protected messages of military significance. The trick, coined as 'Caesar cipher', is one of the simplest and widely known encryption techniques. The writer took the liberty to apply this technique in his program called 'FingCryptor'.

"K.I.S.S. = Keep It Stupid, Simple"

In this spirit, the writer has developed this application in order to assist him in his passwords management. The Wikipedia article on Caesar Cipher [1] is the main source as the guide to develop this application. The GUI - graphical user interface, is designed on Qt 4, whereas the codes for this application are written in C++. The writer is also planning to expand this application and making it more complex albeit low security in the future.

The following image shows how to understand Caesar cipher at its fundamental principle - i.e. shifting any letter three steps backwards.

Image 1: Caesar cipher left shift of 3 [1]

The main advantage of FingCryptor: the writer extended the use of this operation on all ASCII characters e.g. '@', '#', '?' etc, including numbers from 0 to 9.

Images 2 and 3 show the usage of FingCryptor.

Image 2: The ciphering on FingCryptor

Image 2: The deciphering on FingCryptor

The first version of this application is available for download at the bottom of this post. 

Source(s):

[1] Caesar cipher (Wikipedia): http://en.wikipedia.org/wiki/Caesar_cipher

REMINDER / WARNING:
  1. For Windows only. (Linux version will be made available in the next development)
  2. This application is NOT intended for any high security objective.
  3. The writer is NOT liable for any security breach - i.e. deciphering by a third party etc.
  4. Use at your own risk.
Have fun!

Download link:

Friday, December 14, 2012

Plotting a pentagram with MATLAB.


Figure: As seen after running the code

This is a MATLAB code to plot the symbol of pentagram on a Cartesian coordinate system. The symbol consists of 1 circle and 1 pentagram - a 5-pointed star drawn with 5 straight strokes.

Basically this algorithm focuses on the getting the coordinates to draw:

(1) the circle and
(2) the horizontal line.

Later the horizonzal line is manipulated to generate the other 4 lines to form the pentagram.



Contents

The variables

n = 2^8; % Number of sampling points
t = linspace(0,2*pi,n); % Interval
noSides = 5; % Number of sides of the polygon
innerAngle = 2*pi/noSides; % Interior angle of a pentagon.

% Variables for the cirle
r = 2; % Radius
h = 0; % Transition distance
k = 0; % Transition distance

xsfact = 1.3; % Factor to extend the display range of the xy-axes.

Equations for the circle

x = r*cos(t)+h;
y = r*sin(t)+k;

Equation(s) for the horizontal line

% The length of the horizontal line
lH = r*sin(innerAngle)*2;
% Distance to the horizontal line from the center
dist_lH = r*cos(innerAngle);
% The definition interval of the horizontal line
xH = linspace(-lH/2, lH/2, n);

Rotation

Here the horizontal line from the previous will be simply duplicated for 4 times. Every point (x,y) will be multiplied with a 2D-rotation matrix.

side = zeros(2,n);
side(1,:) = xH;
side(2,:) = -dist_lH;

side1rot = rot2d(innerAngle)*side;
side2rot = rot2d(innerAngle*2)*side;
side3rot = rot2d(innerAngle*3)*side;
side4rot = rot2d(innerAngle*4)*side;

Plotting

figure,
hold on
plot(x,y, 'r')
plot(xH, -dist_lH, 'r')
plot(side1rot(1,:), side1rot(2,:), 'r')
plot(side2rot(1,:), side2rot(2,:), 'r')
plot(side3rot(1,:), side3rot(2,:), 'r')
plot(side4rot(1,:), side4rot(2,:), 'r')
hold off
axis(xsfact.*[min(x) max(x) min(y) max(y)])
title('Das Pentagramm')


Monday, December 10, 2012

Report on the Seminar: Media and Democracy



On the last Nov. 2 until Nov. 4 of 2012, World University Service e.V. (WUS) through its wing STUBE Hessen (stands for STUdienBEgleitprogramm) organized a weekend seminar with the theme: Media and democracy: On methods and means of mobilization. This event was held in a youth hostel in Fulda, a Baroque city located to the east of the state Hesse. Around 18 foreign students were present, all from numerous Hessian colleges - Frankfurt, Darmstadt, Fulda, Marburg, Giessen and so on. Three presenters delivered talks during separate sessions and it was moderated by a representative of STUBE from WUS headquarter in Wiesbaden (the capital of the state Hesse). This is the writer's report on this event.

For participation on its programs, STUBE targets foreign students from Asia, Africa and Latin America. Students of nationalities such as Mongolian, Chinese, Chilean, Mexican, Georgian, Albanian, Kenyan, Nepalese, Syria etc were spotted during this event.

During the introduction session on the day of our arrival, participants were introduced to the President of the Uni. of Applied Sciences of Fulda, Prof. Dr.-Ing. Karim Khakzar, who was accompanied by his daughter. He expressed welcome to us to the city Fulda and briefly informed us about his college.

The talks/lectures

Among the objectives of this seminar was to discuss some questions on the social media, which is proven to be a critical factor in today's politics everywhere in this world. This was so as many recent and current events - London Riot, Arab Spring, Barack Obama's Presidential Campaign etc, were known of involving a lot of mobilization via social media such as Facebook, Twitter, Reddit and so on. Therefore the invited lecturers were picked from relevant backgrounds - one graduate student of information science, an NGO activist and a journalist who happened to be an active blogger. All talks were delivered in English.

The first talk was delivered by a Vietnamese postgraduate student from Darmstadt, Mr. T.A. Nguyen. He gave a presentation which taught the pariticipants about the Internet and its impacts. Began with the introduction to the Internet, he lead us to the issues of network security, related incidents such as the London Riot and Wikileaks and censorship.

Then Mr. T. Kowohl, a law clerk by profession, talked about NGO-campaigns, mentioning some case studies from Amnesty International, of which he is a member. His objective is to show us the risks and benefits of social media froma legal perspective. He also requested us to form groups, in which the participants were to discuss make suggestions to Amnesty International on how it should conduct its campaigns everywhere.

On the next day, the final talk was delivered by Mr. J. Kucharz. who is the editor of the website http://netzfeuilleton.de/. He mentioned that he wanted to engage us into becoming our own media mogul, by starting to be active in online media. Various successful examples on online media were shown to us - bloggers, authors, YouTube-ers and so on. The Participants have also discussed the question of how they envision the media landscape of the future.

The Baroque city Fulda

That was the writer's second time coming to Fulda - the first one was in January 2009, when the writer went there as a lone wolf. Nothing much has changed since the last time. Prof. Khakzar, who the writer has mentioned above, told us that Fulda has the reputation of being the cleanest city in Hesse. It does not have much attractions for students - i.e. students find this city not so entertaining at nights, hence the weekend life of students here are relatively quiet. This, as Prof. Khakzar has alleged, is contributing to the high rate of students graduating from Fulda. The writer personally would agree with that, since Fulda is located so far away from other major cities in Hesse - 2 hours of train journey from Frankfurt alone to get there.

Nevertheless, some of the participants attending the seminar, went out during the second night in Fulda. They searched for any student-friendly place to have drinks and they have managed to spot a cosy shisha bar. The writer can't recall the price, but the writer would say it was so affordable that one could order one shisha just for oneself alone.

The conduct/behaviour of the students

Some students were found to be very articulate - actively asking questions and expressing opinions, accompanying their points with examples from their respective home countries. However a few of the participants could also be considered as rude, impolite and irritating because they talked to each other during the lectures, half as loud as the voice of the presenter in the approximately 50 m² room.

Apart from that, a few students also were found to be unfocused or diverted from the main objectives of this seminar. Some were even expressing disappointment that current political issues e.g. Arab Spring were not brought into discussion - as they thought this was the purpose of this seminar. As the writer thought this critic was unnecessary and unfair to the organizer, The writer pointed out that they have been not reading the clear descriptions of this seminar on its brochure, which was already distributed much earlier.

During the second / last night in the youth hostel, some students who were staying (not going to the shisha bar), used the seminar room as a place to put on some loud music and dance. They were having fun until one 40-year-old-plus man, who happened to be another guest the hostel, came to them and gave a threat, telling them to stop partying or he'll complain tomorrow to the hostel admin, saying that this would be their last time to come here. That was very ironic, since this hostel was supposed to be a youth hostel.

Summary

This seminar can be considered as successful in achieving its objectives. Participants were exposed on the availability of social media as a very useful tool in promoting their causes - be it political or anything else. Participants generally found the conducting of the seminar in English very favorable. The seminar has motivated the writer to be more active in using social media, hence by being active again in writing on this blogspot. The venue - a youth hostel in Fulda - it was a good place to hold a instructive events such as this, but located very far from the central  part of Fulda.

Thursday, November 15, 2012

Easy Curve Fitting with MATLAB



Basically this exercise is about an easy and common curve fitting, which is used on a set of raw data points. The book 'Mathematische Formelsammlung' by Lothar Papula was referred for this exercise and its particular chapter is 'Ausgleichs- oder Regressionsparabel'.

Your mission, should you choose to accept it, is to fit a parabolic curve of the form y(x) = a*x^2 + b*x + c, to the given set of raw data points.

At the end of this post, I've included the link to download the M-script file.

Raw data
x = [-3:1:5]';
y = [-3.94 -1.47 -4.66 -3.21 0.84 7.24 15.58 27.94 42.59]';
[n,m] = size(x);
Calculation
The curve parameter a, b and c can be determined from the method of least squares (German- Methode der kleinsten Quadrate), which uses linear equation system with 3 equations and 3 unknowns.

x4 = x.^4;
x3 = x.^3;
x2 = x.^2;

sx4 = sum(x4);
sx3 = sum(x3);
sx2 = sum(x2);

sx = sum(x);
sy = sum(y);

x2y = x2.*y;
xy = x.*y;
sx2y = sum(x2y);
sxy = sum(xy);
Formation of the known matrices
The targetted matrix equation is as follows: A*K = vekb. Out of those 3 matrices, A and vekb are known.


A = [sx4 sx3 sx2;...
    sx3 sx2 sx;...
    sx2 sx n];

vekb = [sx2y; sxy; sy];
Determination of the curve parameter
The matrix K consists of the parameters - a, b and c, that we sought after. Simply multiply the inverse of A and vekb, both gained from the previous step.
K = inv(A)*vekb;
Generation of new data points
By using the gained parameters in K, new points can now be plotted.


yneu = K(1)*x.*x + K(2)*x + K(3);

Plotting

The displaying of the result.

M-Script code:
MV_Blatt_1_Aufgb5.m
p/s: just in case that you're not using MATLAB or Octave, that file can also be viewed in normal text editor =P

Thursday, September 13, 2012

Mission: Get them to study in Hessen



On the last Sept. 3, 2012 I was invited to deliver a talk to the Germany A-Level Preparatory Program (GAPP) students at the German-Malaysian Institute (GMI) in Bangi, Selangor.

My presentation's intro slide


I prefer to refer the GAPP students as the Redshirts - because of their uniform, which I also wore once as I was one too from 2003 to 2005 there.

Here I would like to apologize for putting too much German terms on my presentation slides. Many of the words were too new for them. My intention was only to introduce them those words that they WILL eventually come by again, if they are to study in Germany.

So, as a friendly gesture, I hereby release the Powerpoint file online for the Redshirts to download. It has been added another slide in the end - a list of the German words which were used in the presentation slide with their similars in English.

Studieren in Hessen - Ein Vortrag von Hafiz Jaafar.

I wish you all the best, Redshirts.

Sunday, August 19, 2012

Image Processing with FPGA




Typical solutions of image processing, which are always seen in university laboratories, are run fully with the CPU of the computers which apply them. Those solutions, usually of real-time type, require a large memory capacity of each computer’s RAM. Hence the burden on both the CPU and RAM is high, which will slow down the computer and in the worst case: it will crash or cause a hang. Therefore FPGA – field -programmable gate array, is increasingly applied as an extra hardware to the computer to assist the task of running the image processing solutions. This article discusses a recent laboratorial test for image processing with FPGA, which was conducted by Mr. J.P. Bernecker and the writer, two postgraduate students of University of Applied Sciences of Darmstadt (Hochschule / HS Darmstadt). The test result showed that a real-time solution can be easily executed on a low performance computer with the help of FPGA.

NOTE: This article is written as a translated simple excerpt from the test report which was produced by two students mentioned above and was originally written in German language. Among the sources are named in the end.

During the Summer Semester 2012 at the HS Darmstadt in Germany, the students of the postgraduate course Optical Engineering and Image Processing (Optotechnik und Bildverarbeitung) had to run different laboratorial tests for the subject Industrial/Applied Image Processing (Angewandte Bildverarbeitung). The writer was paired with his lab partner to run 2 tests for image processing which used FPGA.

The other tests available to those students were such as inspection of liquid mixture using infra red camera, observation of the Venus transit etc.

Figure 1 - Linescan camera Basler Sprint spL4096 - 70 km
The test was conducted using two main instruments – a linescan camera (Zeilenkamera) and a frame grabber card, which comes with the field-programmable gate array (FPGA). The linescan camera has only 1 row, hence 1-dimensional, of pixel, which is different than conventional cameras which use CCD or CMOS chip with 2 dimensional array of pixel. The linescan type is mainly utilized in barcode reader, fax, scanner etc. In the following Figure 1 the camera which was used for this task is depicted along with its sensor. This is a model of Basler Sprint spL4096 – 70 km, with 4096 pixel along its column.

FPGA
FPGA is an integrated circuit, into which a logical circuit can be programmed. Alternatively it can be understood as a reuseable silicon chip. To program an FPGA , high languages such as VHDL (Very high speed integrated circuit Hardware Description Language) are used. The FPGA has diverse, prefabricated logic blocks, of which the purposes are to comprise the logical connection of conditions of the input signals to the output signals and to inquire as well as to set the conditions in periphery elements over specific I/O blocks.

With the logic blocks such chips can be so configured that they implement certain hardware functions. The configuration files originate from the compilation of digital algorithms that are developed into softwares.

Framegrabber
Figure 2 - Frame grabber Spartan XC2S 600 E-FPGA
The FPGA chip which was used in this test is a type of Spartan XC2S 600 E-FPGA, a product of the firm Xilinx Inc. This chip is mounted onto a frame grabber MicroEnable III-XL (see Fig. 2), which is produced by the firm SiliconSoftware. A frame frabber is an intelligent card/electronic device for high quality image acquisition and processing. The frame grabber sets up the connection between the camera and the computer.




Why Image Processing with FPGA?
FPGAs are used to reduce the large data streams from hardware into frame grabber. In FPGA-assisted image processing, the necessary computing power for image analysis is significantly decreased. This is the result of less work processes that fall to the CPU/processor, which does not have to partake in the procedures of image analysis. Therefore the latency/time delay from the image acquisition at the input until the output after the processing is notably recduced. Examples of image pre-processing with the help of FPGA are image transformationss, corrections of shadow effects and binary morphology.

The Test: Oscillating String
Figure 3 - Setup of the test
The test which was given to this 2-man groupd consists of 2 parts: Static image of a rotating roller and the swinging string. The former’s purpose is to teach students about the parameterization of linescan camera.

However this article will only discuss more of the latter, as it is directly about the application of FPGA as image processor. The objective of this test part is to detect the oscillation of a guitar string via the linescan camera (see Fig. 3)





Figure 4 - Oscillation of the guitar string
- an inverted gray level image
In the process of detecting the oscillation, the center of gravity (COG) of every image row and the instantaneous position of the string will be determined (see Fig. 4). With those determined COGs, an audio file of WAV-format will be generated, which replicates or recreates the detected oscillation of the guitar string. This WAV-file can be easily played on conventional media players. Audacity, an open source software, was used in this test.






Figure 5 - The VisualApplet design
which was used to detect the oscillation

The following image (Fig. 5) shows a design – a program which is developed on the platform VisualApplets. This design was a work of a previous group (students Mr. U. Häberle and Mr. Klöß) and was allowed to be used in this test to ease the current group’s jobs. The programming on VisualApplets is quite complex and requires more time than the allocated for this test, especially for beginners. One can notice that the interface in VisualApplets is similar to those of MATLAB-Simulink and LabVIEW.

This design consists of the following steps – loading the images in the buffer, inverting, converting to binary images and the generation of a WAV-file.

Due to some problems, the design above has been synthesized – i.e. a C++ source code is generated from the design and the program is run from Visual Studio, instead of the proper platform microDisplay, which comes along with VisualApplets in the complete package.

The outputs of every execution of this program are always the same -  a TXT-file which lists all the calculated COGs and the expected WAV-file.

With Audacity, the oscillation or displacement of the guitar string is visualized and further deductions can be drawn (see Fig. 6).

Figure 6 - The playback of the oscillation via Audacity
From this image, one can easily notice that the guitar string was plucked five times during the period of image acquisition.

Conclusion
This test has served as a platform to deliver a good insight into the possibilities and problems that are associated with FPGA technology. The C++ program which was run from Visual Studio has yielded comparable and good results. Apart from that, the execution of the software caused frequent crash, hence the frequent restart of the computer. Such tests should use only prepared applets, as the developing of one’s own applet is too extensive for an experiment which must be done in only two period blocks (90 minutes each) per session/week.

Sources

  1. National Instruments Tutorium: Einführung in die FPGA-Bildverarbeitung mithilfe des NI LabVIEW FPGA Module (Jan 04, 2012)
  2. National Instrumens Tutorium: Einführung in die FPGA-Technologie: Die 5 größten Vorteile (May 20, 2012)
  3. SiliconSoftware - Official website http://www.silicon-software.de/
Nisi Dominus Frustra.