Skip to main content

Posts

Showing posts from October, 2009

Experiences with OpenCV

OpenCV has really lots of useful classes and features.
The square detection for my virtual reality class work is being made with it.

Unfortunately, on my tests, I was detecting squares which I didn't want the software to detect. Like on the image below:It would be much better if I could do the image analysis only inside the laptop screen. "Googling" on "OpenCV image crop" I had reached the nashruddin.com (OpenCV Region of Interest - ROI). This blog has a good explanation on how to crop (extract the region of interest) from a image.
With those informations I got the following result for the same frame:

Now I have to check the area of the detected squares. At the web archives of the computer geometry class mailing list, from the Illinois University, google had shown me one algorithm to calculate the area of a closed polygon, as follows:
Let 'vertices' be an array of N pairs (x,y), indexed from 0
Let 'area' = 0.0
for i = 0 to N-1, do
Let j = (i+1) mod N
Let…

Becoming father...

After 4 years of marriage we will finally have our first kid.

My wife is writing a blog with more details (in Portuguese). But which is letting me more exited about this near future is the new excuse to buy toys. The chart below from graphjam illustrates well:


see more Funny Graphs

And here is one echo scan image made when we were with 12 weeks of pregnancy:

Developing PlayStation2 Games

The I finally have a PlayStation2 at home. Now it is time to start looking for tools for game developing for it.

The first place google has shown was http://ps2dev.org/. The first look has been promising. Besides the PlayStation2 related pages, it also has tutorials and articles related to the PlayStation3 and the PSP.

I hope to sooner be posting something about my experiences developing for the PlayStation2.

The results should probably be tested with some PlayStation2 emulator (http://pcsx2.net/, http://www.emulator-zone.com/doc.php/ps2/)

How many times each user has logged in

With this line, we can check how many times our users had logged in with SSH:

cat /etc/passwd | cut -d ":" -f 1 | sort | uniq | while read line ; do echo -n $line" "; zgrep "user $line" /var/log/auth.log* | grep -i ssh | grep -vi fail | grep -vi invalid | wc -l; done | sort -n -r -k 2

On my system, the only user which has logged in was my own user:
filipi 52

And for non SSH logins:
cat /etc/passwd | cut -d ":" -f 1 | sort | uniq | while read line ; do echo -n $line" "; zgrep "user $line" /var/log/auth.log* | grep -vi fail | grep -vi invalid | wc -l; done | sort -n -r -k 2

Checking auth.log for ssh brute force attacks

As I am letting my personal computer always on, as a homelinux server, I decided to check if someone is trying to breaking in with SSH brute force attacks.

First I did a grep for fail at the /var/log/auth.log. (grep -i /var/log/auth.log)

And I got lots of lines with the string "fail". With [grep -i /var/log/auth.log | wc -l] I figured out that were 1164 fail entries at auth.log

With an [grep -i fail auth.log | cut -d " " -f 6 | sort | uniq] I checked that were two kind of failed attempts:
Failed
pam_unix(sshd:auth):

So I wrote the following line to check with which users they were attempting to log:
grep Failed auth.log | cut -d " " -f 11 | sort | uniq | while read line ; do echo -n $line" "; grep $line auth.log | wc -l; done | sort -n -k 2

Here, the field position (the number 11 at the above command lines [-f 11]) may change in some systems. At my desktop at work, the username came at the position 9.

Here are the "top ten":
root 2922
user 2884

GNU Octave from PHP without temp files

Of course... How haven't I thought that? Pipes!

I was "googling" about PHP and Octave and I had found some simple approach at a mailing list archive. I had already used Octave with PHP but I had always used temporary files, but pipes are a much simpler approach.

From the mailing list post:
in php
start "octave -q script" with popen

create a string in php e.g. "input_data = [102 10 10 10 10 10];"

write this string to the pipe

in octave

recive the string with fread on stdin
let the eval function do the job
calculate

print the result with printf in php syntax "$result = array(12,10,9,12,)"

php
read the output from the pipe (with php fread)
use phps eval function


but using eval with octave and php is a security risk, to avid eval parse
the matrix wird scanf

this is also not the fastes way to use octave (the octave startup needs a
lot of time)

Plotting with AJAX + Javascript

A friend of mine had written an application which communicates with a small microcotroled board and saves data read from this board on a mysql database. He wants to plot these data on the web. He wrote a PHP script using the GD lib. He did a real good job, but he wants it to plot the data dynamically and an http refresh made things a little ugly. He is now trying to plot directly with AJAX + Javascript. He is trying to use Flot, which is a javascrit for plotting data.
Another usefull resource for realtime web graphics is the CavasDemos.

Regex within PostgreSQL

Regex (Regular expressions) are very useful. I had to make a SQL query to return only the firstname from a table where the field provides the full name.
ideia_onde=# SELECT name FROM users;
name
--------------------------------
Linus Torvalds
Randal Schwartz
Steve Wozniak
(3 rows)

ideia_onde=#
Now, with a simple substring using a regular expression:
SELECT SUBSTRING(name, '(.*?(\\s))') FROM users;
substring
-----------
Linus
Randal
Steve
(3 rows)

ideia_onde=#
What do I did?
The substring function extracts from the name field everything (.*) until (?) a space character (\\s).

Experiences with Tecgraf Libraries

My advisor is always right. So I have decided to take a look at Im lib, from Tecgraf.

As a learner by example, I first tried to compile and run the examples provided with Im lib, but most of their examples came written in lua and I need to write my code in C (or C++). Fortunately there were 6 examples written in C++:
glut_capture.cim_copy.cppim_info.cppim_view.ciupglview.cproc_fourier.cpp
But, I wans't use glut (discarted glut_capture.c and iupglview.c)
So I've choosen im_view.c to try to compile, and the torture has started. There wans't any doc, readme or anything which tells something on how to compile the examples. The only clue was the comments written on the source header:
/*
IM 3 sample that shows an image. Needs "im.lib", "iup.lib", "cd.lib" and "cdiup.lib". Usage: im_view Example: im_view test.tif Click on image to open another file.
*/
Well, I had discovered that I was needing three more libs from Tecgraf to compile this ex…

Converting a video file to lots of images

Still for that grad school work on stereo video, I want to convert the videos I made to a bunch of bitmap images.

With linux and ffmpeg it is easy. It is just type:
ffmpeg -i video.dv image%03d.bmp
There are more ffmpeg cheats at:
http://webupd8.blogspot.com/2009/08/ffmpeg-cheat-sheet-19-best-practices.html

Here is a couple of links very useful:

Video convertion cheat sheat (http://www.m3fe.com/31765/)Video editing software (http://www.tech-faq.com/Video-Editing-Software.shtml)
Specifically, the command line I was looking for is:

ffmpeg -i esquerda.dv -f image2 foo_%02d.bmp

Google Bookmarks And Google Notebook

As an advise from my grad school advisor, I am now putting all references I am reading for my master's thesis on google bookmarks. There also is a short cut to directly add a page on ones bookmarks, using a simple firefox bookmarks toolbar button. The best part, is that with google notebook, another tool, one can share the bookmarks. So my advisor can check what I am reading.

The URL of my public bookmarks is:
https://www.google.com/notebook/public/02836905453520795692/BDT3iIgoQh_GewpYj