Wednesday, September 1, 2010

gst-launch examples

1. read and display YUV
gst-launch filesrc location=movie.yuv ! videoparse framerate=20 width=640 height=480 ! xvimagesink
OR
gst-launch filesrc location=movie.yuv blocksize=460800 ! video/x-raw-yuv,format=\(fourcc\)I420,width=640,height=480,framerate=5/1 ! ffmpegcolorspace ! xvimagesink
but here framerate setting does not work.

Thursday, August 12, 2010

Gnome problems

1. gnome-panel 2.28.0 has a bug in Karmic Koala. When you set it up to auto-hide it starts looping and takes almost all CPU. And auto-hiding does not work. One cannot even get back to the access to panel settings to disable auto-hide. You can start gconf-editor and under panel->toplevels->top_panel_screen_0 disable auto-hide option.

Tuesday, June 22, 2010

memset speed vs memcpy speed

Below i post some piece of code I wrote for memset testing. It's C.
Memset can be 4-5 times faster then an ordinary loop.
There is also one feature which should be pointed out.
When loop and memset operate on the same array and loop is first in order (memset follows the loop), memset can be 10 times faster (probably due to cache usage). It does not work the opposite way. If memset goes first and loop goes second the memset speedup is 4-5 times again.
The array is one dimension - why the compiler does not take advantage of cache. Or maybe the cause of speed up when memset goes after loop is better vectorization?
If arrays are totally different memory areas, the speedup for memset is again 4-5 times.

Try it yourself if you wish and please comment. I have used gcc 4.4.1


#include
#include "time.h"
int main()
{

unsigned int val = 253,val2=223;
const int size = 7000;

//unsigned int test[size][size];
unsigned int *test,*testloop;
test=(int*)malloc(size*size*sizeof(unsigned int));
testloop=(int*)malloc(size*size*sizeof(unsigned int));
if (test == NULL)
{
printf("cannot allocate so much memory, size: %d ", size);
return;
}

int i,j;
double loop_time,memset_time;

double old_time = (double)clock();///CLOCKS_PER_SEC;
// printf("took %5.3f seconds \n", total_time);

for (i=0;ifor (j=0;jloop_time=(double)clock() - old_time;
memset_time = (double)clock()- old_time - loop_time;
printf("Loop took %5.3f ticks \n", loop_time);
printf("memcpy took %5.3f ticks \n", memset_time);
free(test);
free(testloop);
free(struct_array);
free(struct_array2);
free(struct_array3);
}//main

Memcpy works slower than assignment
I had to check it and it is truth. The assignment runs faster then explicit memcpy. All tests were done using gcc and g++ 4.4.1. Here is the code for struct copy. I tested memcpy and loop in separate executions (that's why memcpy is commented out)

#include
#include "time.h"
#include
int main()
{

unsigned int val = 253,val2=223;
const int size = 7000;
class test_struct
{
int a;
int b;
float dupa;
double s;
public:
test_struct() {};
};

unsigned int *test,*testloop;

test_struct *struct_array = new test_struct[size*size];
test_struct *struct_array2 = new test_struct[size*size];

test = new unsigned int[size*size];
testloop = new unsigned int[size*size];

int i,j;
double loop_time,memset_time;

double old_time = (double)clock();///CLOCKS_PER_SEC;
// printf("took %5.3f seconds \n", total_time);

for (i=0;i for(j=0;j struct_array[i*size + j] = struct_array2[i*size + j];

//memcpy(struct_array2,struct_array,size*size*sizeof(test_struct));
loop_time = (double)clock() - old_time;

memset_time = (double)clock()- old_time - loop_time;
printf("Loop took %5.3f ticks \n", loop_time);
printf("memcpy took %5.3f ticks \n", memset_time);
//delete(test);
//delete(testloop);
delete [] struct_array;
delete [] struct_array2;
delete [] test;
delete [] testloop;
}

Saturday, June 19, 2010

ffmpeg examples

1. cropping from avi:
ffmpeg -i input.avi -croptop 44 -cropbottom 46 -cropleft 56 -cropright 36 -sameq -s 640x480 cropped.yuv
2. cropping yuv:
ffmpeg -s 640x360 -i source.yuv -cropleft 120 -cropright 120 -croptop 60 -cropbottom 60 target.yuv

Thursday, May 27, 2010

IEEE 1394 camera tricks

1. reset the bus
dc1394_reset_bus
2. Showing the capabilities of the camera
cd /sys/bus/ieee1394/devices/[node]
(you can check nodes number using dc1394_reset_bus)
grep . *

Automake - conditional compilation

I want to compile some part of the code only when library (OpenCV) is detected:
In configure.ac
dnl check if opencv is installed
PKG_CHECK_MODULES(OPENCV,
opencv >= 2.1.0,
HAVE_OPENCV=yes, HAVE_OPENCV=no)
if test "x$HAVE_OPENCV" = "xno"; then
AC_MSG_NOTICE(no OpenCV library with version >= 2.1.0 found - rectify plugin will not be available)
elseif
dnl if yes set flags and libs
AC_SUBST(OPENCV_CFLAGS)
AC_SUBST(OPENCV_LIBS)
fi
dnl set the variable for makefile
AM_CONDITIONAL(I_HAVE_OPENCV, test "x$HAVE_OPENCV" = "xyes")
---------------
In Makefile.am
if I_HAVE_OPENCV
"do smth"
else
"do smth else"
endif

A bit more about conditionals in makefiles is here

Tuesday, May 18, 2010

Firefox plugin does not work with the newest Firefox version

The problem comes when the plugin version is not updated on addons.mozilla.org and firefox claims it is not compatible with current version. Steps to solve this issue:

1. Donwload .xpi file (right click on "Add to Firefox" button.
2. Change extension to .zip
3. edit install.rdf file so that maxversion matches the current version of your firefox
4. save changes
5. change .zip back to xpi
6. Drag and drop .xpi on firefox.

More on this can be found here

Sunday, May 9, 2010

libdc1394 operation

dc1394_video_set_framerate

Saturday, May 8, 2010

Linux command line tricks

1. update gnome config from the command line. In that case turn on proxy usage in the system.

gconftool -s /system/http_proxy/use_proxy -t bool true

2. change file encoding from dos to unix and back:
fromdos, todos

3. detect and convert encoding of text files
enca

Thursday, May 6, 2010

QT creator tips and tricks

1. The problem comes when debugging:
Internal error: pc 0x4098b8 in read in psymtab, but not in symtab
Internal error: pc 0x4098b8 in read in psymtab, but not in symtab
Internal error: pc 0x4098b8 in read in psymtab, but not in symtab
Internal error: pc 0x4098b8 in read in psymtab, but not in symtab

To solve it go to Tool->Options->Debugger->gdb location and change the filename to point to the gdb binary stored in the qt sdk. In my case it is /home/user/qtsdk/bin/gdb

libraries maintenance

How to check the necessary g++ options:
1. pkg-config opencv --libs --cflags
2. ldconfig -v - shows the libraries stored in ld.so.conf
3. locate [libraryname] - searches for files
4. pkg-config opencv --modversion - shows the version of opencv library installed

Wednesday, May 5, 2010

basic irc operation

registering nick:
/msg nickserv register PASSWORD EMAIL
identifying after entering:
/msg nickserv identify PASSWORD

Friday, April 30, 2010

Mercurial: Create a new local repository and clone it to the remote repository.

Yes. Mercurial sucks.

If you were considering going
deeper into it. Forget it.
Does any high-end super glorious system give you a suggestion to delete
all your modifications silently? Yes. Mercurial.
After one day of hard work I want to commit.
hg commit -m 'Great job'
then great mercurial suggests:
abort: unresolved merge conflicts (see hg resolve)
Yes. It's telling you to run hg resolve. And if you do it with option -all you will loose all fucking changes since last update in a local directory.
Fuck this system.


If you really want to know how to clone to the remote repo - read below.

Say you have /home/joe/my_source direcory where you have your code and you want to make a new remote repository. You have to have ssh access to the remote repository.
cd /home/joe/my_source
hg init #create new local repo
hg add [files you want to add]
hg commit -m 'initial changeset' #commit initial changeset
hg push #push changes to repo
You migh want to use hg push ssh://repo@myrepo.com:22//home/repo/my_remote_source if you get "abort: repository default-push not found!" error. I don't know how to fix it yet.

Cloning:
cd /home/joe
hg clone my_source ssh://repo@myrepo.com:22//home/repo/my_remote_source
A note for cloning. Normally you clone from remote repo to local directory. My example is opposite. If you want to import repository to local directory then look elsewhere (it's easy).
The command above creates my_remote_source directory on the server and clones the local repository (from /home/joe/my_source) to myrepo.com.
'//' means absolute path. If you use '/' after port number it will be relative to home directory.

Now you have to:
ssh repo@myrepo.com
cd my_remote_source
hg update

That's done you should have your repo cloned. There is a way to make the last step automatic

Thursday, April 29, 2010

Setting up FireWire (1394b) machine vision camera

Currently udev on Ubuntu 9.10 has a problem that it does not create firewire video devices in /dev
For proper working of machine vision camera one has to have loaded:
  • ohci1394
  • ieee1394
  • video1394
  • raw1394
and rw rights set up for /dev/raw1394 and /dev/video1394/[0-3]

My fix for this was:
1. Add to /etc/modules (loading modules during boot)
  • raw1394
  • video1394
Setting the "rw" rights:
You can create /etc/udev/rules.d/51-raw1394.rules and add this line to that file:
KERNEL=="raw1394", GROUP=="video"
That way udev will change group belonging of /dev/raw1394 to "video" group.
Of course you have to have this group created (you can use groupadd for this).
Adding yourself to the group:
sudo usermod -a -G video joe
Checking if this was successful:
groups joe
You might want to restart udev to apply changes in udev rules.
sudo service udev restart
raw1394 is done. Now we have to fix /dev/video1394/[0-3]. I have to add startup script to make directory and nodes for my video1394 devices.

I created file /etc/init.d/1394:
touch 1394
changing rights:
sudo chmod +x ./1394
I have to put this text to 1394 file:

#!/bin/bash
mkdir /dev/video1394
mknod /dev/video1394/0 c 171 16
mknod /dev/video1394/1 c 171 17
mknod /dev/video1394/2 c 172 18
mknod /dev/video1394/3 c 173 19
chmod a+rw /dev/video1394/0
chmod a+rw /dev/video1394/1
chmod a+rw /dev/video1394/2
chmod a+rw /dev/video1394/3

This creates the nodes and sets proper rw rights.
I have to put this as startup script:
update-rc.d 1394 defaults

Finally coriander does not complain and my cameras seems to work.
Thanks to Point Grey for sharing the info

Setting up Ubuntu

System: Karmic Koala (Ubuntu 9.10)
Mozilla Firefox extensions I use:
  • Incredible bookmarks ( to search in bookmarks)
  • Find in Tabs
  • Xmarks (to sync my bookmarks on many computers, and to not worry about exporting and importing bookmarks)
  • Manage Folders
The problem with mc in gnome-terminal ( function keys are not working):
In gnome-terminal go to Edit -> "Keyboard Shortcuts" and disable two items: "Enable menu access keys" and "Enable the menu shortcut key".


Seems I lost X for a while. I changed manually xorg.conf. I just run
nvidia-xconfig
in the console and xserver is back. I have found some interesting hints here on how to set up refresh rate in xorg.conf. I am using nvidia-glx driver and nvidia-settings . It's nice in configuration.

And midnight commander bug. It does not want to store configuration file. It's enough to create .mc directory in user's home directory and it works fine.

Checking ubuntu version:
sudo lsb_release -a

Upgrading Ubuntu:
1. Put new repositories to /etc/apt/sources.list (backup old file)
For 10.04 (lucid )
deb http://pl.archive.ubuntu.com/ubuntu/ lucid main restricted
deb-src http://pl.archive.ubuntu.com/ubuntu/ lucid main restricted
deb http://pl.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
deb-src http://pl.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
deb http://pl.archive.ubuntu.com/ubuntu/ lucid universe
deb-src http://pl.archive.ubuntu.com/ubuntu/ lucid universe
deb http://pl.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb-src http://pl.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb http://pl.archive.ubuntu.com/ubuntu/ lucid multiverse
deb-src http://pl.archive.ubuntu.com/ubuntu/ lucid multiverse
deb http://pl.archive.ubuntu.com/ubuntu/ lucid-updates multiverse
deb-src http://pl.archive.ubuntu.com/ubuntu/ lucid-updates multiverse
deb http://security.ubuntu.com/ubuntu lucid-security main restricted
deb-src http://security.ubuntu.com/ubuntu lucid-security main restricted
deb http://security.ubuntu.com/ubuntu lucid-security universe
deb-src http://security.ubuntu.com/ubuntu lucid-security universe
deb http://security.ubuntu.com/ubuntu lucid-security multiverse
deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse

deb http://pl.archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse
# deb-src http://pl.archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu lucid partner
# deb-src http://archive.canonical.com/ubuntu lucid partner
# deb http://dl.google.com/linux/deb/ stable non-free
deb http://packages.medibuntu.org/ lucid free non-free
# deb-src http://packages.medibuntu.org/ lucid free non-free
deb http://archive.getdeb.net/ubuntu lucid-getdeb apps games
# deb-src http://archive.getdeb.net/ubuntu lucid-getdeb apps games
# kadu - jeszcze nei ma dla lucid:
# deb http://ppa.launchpad.net/patryk-prezu/ppa/ubuntu karmic main
# wine
deb http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu lucid main

2. apt-get update
3. apt-get dist-upgrade

Samba share set-up
Install smbclient, smbfs
put
//shareserver/share /local_folder cifs user=[login],pass=[password],rw,uid=[me],gid=[mygroup] 0 0
to /etc/fstab