Sayfalar

2 Aralık 2014 Salı

Temple Matching with OpenCV

If you want to find an object in an image , you can use temple matching methods. I try to detect marker in video , and I try these methods. But unfortunately , temple matching methods in OpenCV are not sufficient because they are not invariant to illumination condition and scale sizes.

 You can see in my code there is a matching method , there are a lot of options , their approach like this ;



















My Code ;
















Result ;



As you can see in result image a rectangle appear bottom but in the middle there is me and I pasted my marker on to my chest .In video sequence nearly 30 seconds I am moving very slowly but this method cannot find right place. In this week , I will try more accurate method for recognizing object and tracking.If I do any progress, i will share the results.




References; http://docs.opencv.org/doc/tutorials/imgproc/histograms/template_matching/template_matching.html

24 Kasım 2014 Pazartesi

SIFT Algorithm

SIFT is very popular method in Computer Visioni created by Dr.Lowe.I prepared a presentation about this.Link are here ;

http://web.itu.edu.tr/~aygunme/sift.pdf

After the midterms maybe I can share an Octave or Matlab code.

2 Kasım 2014 Pazar

Octave and Image Tool

      Octave is alternative program for MATLAB, which is a GNU project and can run on Linux systems.It is free and it's useful for  a lot of operations like MATLAB.I use Octave for Computer Vision.Like Matlab , octave has same tool include some ready function for some compex perations..Installation of octave is very simple with sudo apt-get install octave is fine but for normal usage.If you want to use Image tool you must install 3.8 version or later.

Download version 3.8 later , octave and use this command for installing pure octave.

tar xvf octave-version.tar.gz
cd octave-version
./configure
make
sudo make install

make step is a little bit long so you can use make -j number , number here number of the your core so you can parallel this step ,and time is decrease.

Then we must install package image.But most of the package have pre-package, so you have to install another package , here dependencies image tools

image ->general
           ->signal->control

for install package Download  and give the command on octave pkg install package_name.tar.gz

You must start the control,then signal and general last install image tool.

Then you must load the image package with : pkg load image 

Then you can use a lot of ready image-tools functions.

6 Ekim 2014 Pazartesi

Smart Pointers

Smart Pointers


            Smart pointers come with C++11 standarts.They help us to handling about memory managment topics.In modern languages there are garbage collector that manage the object life times and object's memories.In c++ when we create a object we must be delete the object , otherwise the memory which is used this object will be useless.There are four smart pointer in C++11 , but there are another smart pointers in boot libraries.Since they are not standart I wont cover in this article.

       We must give the flag -std=C++11 in GCC and add the library <memory> when we use the smart pointers.

auto_ptr

     First smart_pointer is auto_ptr.It is not as smart as other smart pointers.When we create object we must be delete when we finished job about this object.


Obje* ptr = new Obje();
ptr->Fonksiyonlar();

delete ptr ;

         But when we forget the deleting there will be extra memory usage.
When define the auto_ptr ;
auto_ptr<T>ptr(new T); We use the this declaration.T is the type of the pointer and ptr is the name.With Ptr-> we can access the object elements and functions.When a auto_ptr assign a object and this object's life time over it deleted automaticlay. It have two useful functions : reset () and release (). reset is kill the object and create a new one , but release is only finished the ownership.

prt.reset(new T); // reset usage
T* p3= ptr.release() ; // ownership finish

delete p3; // delete the pointer 


We cannot use the auto_ptr for STL containers and we shouldn't assign a auto_ptr to another one.Because when assign the first one lose the ownership.
There are a idiom for not losing ownership it is const idiom we can only add the const.

const auto_ptr<Test> pt (new Test(2)); // like a normal auto_ptr

shared_ptr

It is for sharing a object .We can assign two pointers to a object without losing a ownership.We can assign two shared_ptr but never two shared_ptr points to each other because of strong reference counting they cannot be deleted.Declaration of shared_ptr is like auto_ptr
shared_ptr<T> sptr(new T); 
We can use the shared_ptr for the arrays but we must de declare a deletion operation like ;
shared_ptr<int []>p (new int[10],[](int* p) {delete [] p;});


       We a shared object points a object strong reference will one if another one do it will be 2.When the strong reference is zero object will deleted.It is good to sharing a object.But when cyclic reference happen the object cannot be deleted because strong reference never will be 0.For example;
void main()
{
std::shared_ptr<A> x=std::make_shared<A>();


x->ptr = x;// never deleted
}



We can handle this situation with using another smart_pointer weak_ptr

weak_ptr
       weak_ptr using for breaking cyclic reference.But we(programmers) must be investigare where the cyclic reference. weak_ptr cannot be exist without a shared_ptr.weak_ptr take a shared_ptr as a parameter when it is declareted.Like;

weak_ptr<T> wptr(sptr); // sptr : a shared_ptr


We cannot use the -> or . İn weak_ptr.If a weak_ptr assign a shared_ptr strong reference wont increase.So we can the break cyclic reference.
It have two functions : lock and expired ().expired return is expired or not.lock return a shared_ptr whic it assigned.

 We can solve the danglin pointers with using weak_ptr;

unique_ptr

      Last one is unique_ptr. It is like shared_ptr but but there is no sharing thing.a unique_ptr can assign to another one.We can use the unique_ptr for arrays or contaioners without create a delete operation.It have two function reset and release. Reset is reset all thing resource,ownership but release is only finish the ownership.Here a sample code;

26 Eylül 2014 Cuma

Multi-Threading In Android and Handler Class - I

Multi-Threading In Android and Handler Class - I 

Multi-Threading in Android

When I started research this topic first question about threading is why i need threads? There is always tags like fast,usable,multicore .etc. All of them good tags which i interest in all of type programming language :)With multi-thereading our app's will be more fast and more useable,but WHY ? Java,C or C++ are written in very past , and all of them create for single core processor but today we have a lot of processer even in mobile phones.And today we can use multi-cores with same ways in these languages.In Java multi-threads is a way to use this power.In android we can use regular threads as in Java but we must be consider about Android threads(UI Threads) and some classes.

In android there is a class which responsible to handle  topic about threads,and  it's name is Handler class:).With messages all of the threads comminicate with each other in this class.It is simple to create a handler

Handler handlerObject = new Handler(); 

We use the Runnablers for multi-threadings.They are type of thread whic can execute their body or call another functions etc.They include a abstract method void run() all of the threads must be have this method.

class ClassName implements Runnable 
{
Public void run() 
{
// Body of method
}
}

When we use the Handler in our android project we must be add import android.os.Handler; lines in aour projects.
And in our project we create a handler like on the top.

Handler maygun = new Handler(); 

And then we can create a Runnable

Runnable run = new Runnable() 
{
public void run()
{
// Our functions
  }
};


I will continue with Handler Mechanism and AsyncTask in next blog post.

26 Ağustos 2014 Salı

C++ 14 Announced

https://isocpp.org/blog/2014/08/we-have-cpp14

C++ 14 standard has been announced.C++ 14 have a lot of new capabilities and this capabilities is made C++ more powerful and modern language.Here a blog post for new features about C++14.

Clang 3.4.x and newest version of GCC support C++ 14 standard.

Here some of the features which really affect me  ;

N3532  - Dynamic Arrays 

N3534 - C++ Pipelines

N3554 - A Parallel Algorithms Library for C++

N3559 - Proposal for Generic (Polymorphic) Lambda Expressions


Dynamic Arrays will play huge role for memory management in C++ projects.

C++ Pipelines and Parallel Algorithm library is also very important , because all of the computer architecture in today have multiple core system and we must use all of the power for strong and fast software.

Lambda  came with C++11 but now it have more power in C++.


1 Ağustos 2014 Cuma

Haskell Day6

Basic I/O

Here is the most classic program ever :)

main = do
     print(“Hello Word”)

If we want to get input in Haskell we can use getline function for strings,integers or other basic input data. For example :


main= do
       putStrLn "enter age"
       age <- getLine
       putStrLn("Hello " ++ age ++ " boy")

Let do some fun thing with simple ı/o and some condition situations :)

main= do
          putStrLn "enter age"
          age <- getLine
          if read(age) > 50
                  then do print("You are too old man")
          else
                 do print("Yeah men you have a lot of time for Haskell !")


In line 2 we enter the value of the age.line 3 take the argument and equalize the value of the age variable. In line 4 with read function we can compare a string and a integer because Getline function get string and read function change it.then line in line 4 if do the condition things and “then do” parts is returning part.