Archive for the ‘General’ Category

Tools:
It is assumed that OpenCV is already installed.

The goal:
To make a perspective transformation on an image using homography and overlay it onto the other image.

Input :
Two image files – “main image” and “logo image”.
main

logo

Output:
Overlayed images

out1

out2

 

Algorithm
The “logo image” is overlayed onto the main image. We need a homography matrix to transform the image points of “logo image” before it is overlayed. To calculate a homography matrix we need 4 correspomding pair of points from “logo image” and “main image”. The 4 points for “logo image” are taken as the four corners of the image where as the 4 points for “main image” are chosen by the user. Remember each of the 4 points in each image is of the form (x,y).

Once homography matrix is calculated the “logo image” is perspectively projected onto the “main image”. In this implementation the pixels of “logo image” replace the pixels of “main image”. Users can change this to do any other kind of blending.

Running the code:

Github code
Assume that the executable generated is “homography”. The images files(main.jpg,logo.jpg) are passed as two arguments. Note that the image files are present in the Github repository.

$ ./homography main.jpg logo.jpg
The video link with demo :

 Code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <iostream>
#include <limits>
#include <numeric>
using namespace cv;
using namespace std;

// We need 4 corresponding 2D points(x,y) to calculate homography.
vector<Point2f> left_image;      // Stores 4 points(x,y) of the logo image. Here the four points are 4 corners of image.
vector<Point2f> right_image;    // stores 4 points that the user clicks(mouse left click) in the main image.

// Image containers for main and logo image
Mat imageMain;
Mat imageLogo;

// Function to add main image and transformed logo image and show final output.
// Icon image replaces the pixels of main image in this implementation.
void showFinal(Mat src1,Mat src2)
{

    Mat gray,gray_inv,src1final,src2final;
    cvtColor(src2,gray,CV_BGR2GRAY);
    threshold(gray,gray,0,255,CV_THRESH_BINARY);
    //adaptiveThreshold(gray,gray,255,ADAPTIVE_THRESH_MEAN_C,THRESH_BINARY,5,4);
    bitwise_not ( gray, gray_inv );
    src1.copyTo(src1final,gray_inv);
    src2.copyTo(src2final,gray);
    Mat finalImage = src1final+src2final;
    namedWindow( "output", WINDOW_AUTOSIZE );
    imshow("output",finalImage);
    cvWaitKey(0);

}

// Here we get four points from the user with left mouse clicks.
// On 5th click we output the overlayed image.
void on_mouse( int e, int x, int y, int d, void *ptr )
{
    if (e == EVENT_LBUTTONDOWN )
    {
        if(right_image.size() < 4 )
        {

            right_image.push_back(Point2f(float(x),float(y)));
            cout << x << " "<< y <<endl;
        }
        else
        {
            cout << " Calculating Homography " <<endl;
            // Deactivate callback
            cv::setMouseCallback("Display window", NULL, NULL);
            // once we get 4 corresponding points in both images calculate homography matrix
            Mat H = findHomography(  left_image,right_image,0 );
            Mat logoWarped;
            // Warp the logo image to change its perspective
            warpPerspective(imageLogo,logoWarped,H,imageMain.size() );
            showFinal(imageMain,logoWarped);

        }

    }
}


int main( int argc, char** argv )
{
//  We need tow argumemts. "Main image" and "logo image"
    if( argc != 3)
    {
        cout <<" Usage: error" << endl;
        return -1;
    }


// Load images from arguments passed.
    imageMain = imread(argv[1], CV_LOAD_IMAGE_COLOR);
    imageLogo = imread(argv[2], CV_LOAD_IMAGE_COLOR);
// Push the 4 corners of the logo image as the 4 points for correspondence to calculate homography.
    left_image.push_back(Point2f(float(0),float(0)));
    left_image.push_back(Point2f(float(0),float(imageLogo.rows)));
    left_image.push_back(Point2f(float(imageLogo.cols),float(imageLogo.rows)));
    left_image.push_back(Point2f(float(imageLogo.cols),float(0)));



    namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", imageMain );


    setMouseCallback("Display window",on_mouse, NULL );


//  Press "Escape button" to exit
    while(1)
    {
        int key=cvWaitKey(10);
        if(key==27) break;
    }


    return 0;
}

˙˙˙ɯɯH ¿ʇɹɐʇs I op ʍoɥ ‘ llǝM.                                                                                                                             Oops! Let me turn the page this way. Sorry about that! Let’s get started!

I will try to explain the thoughts in a very orderly manner. No , no. I will …. Okay I will write about my experiences in the recent past. No .no. That really sounds too cliche.  Really sorry, I see that the page is already getting dirty. Sometimes thoughts are like speeding cars that we see through our window pane. We see them all but nothing is registered in enough detail if we want them to pen down. This haziness takes a toll shallowing the little left concreteness in my ideas. Okay, I will let the randomness flow. See if you can figure out any pattern in  this randomness!

#When we are young we will completely be ourselves and do only the things that we find are cool . As we grow up we see growing dissatisfaction with our lives. We  want to be that smart chap or that cool movie star or that rich neighbor. We lose our identity in the pursuit of trying to be someone else. Sadly, most don’t realize that  being completely themselves is the coolest they can ever get. It isn’t about what you are in the eyes of other people but it is about what you are to your inner self. All that matters is whether you are happy being absolutely yourself or not. The key is to be  what you want with minimal inconvenience to the people around you. And by just believing what you do, you will be amazed to see how many people you have surpassed whom once you used to look upto.

#Engineering? Arts? Pure Sciences? Music? Dance? Don’t think about whether the career you chose will be commercially rewarding or not if you are really  passionate about it. If you are really passionate about it and willing to put in the extra hard work just go for it. Don’t let money or time dictate your ideas and hinder you from following passions.World will never fail to recognize people who are truly passionate about what they do. Even if your idea is to come up with a new chopstick model world will encourage you. May be someday you will have a google doodle  for being the designer of new chopsticks.You never know. All you gotta do is to show the world your swag. 🙂 As someone rightly said “Do not waste the vast majority of your life doing something you hate so that you can spend the small remainder sliver of your life in modest comfort. You may never reach that end anyway.” You might be the one who has taken a less trodden path but you will take pride in every footstep.

#Appreciate and take inspiration from people who are great in a paricular field but never make yourself low comparing yourself with them.

#In my opinion religion is very similar to an operating system. There is no universally superior operating system. If you started on a Mac as a kid and if that is what you have experienced your whole life then you tend to appreciate Mac better than other operating systems. So is the case with Windows or Linux. It is just about what you are more comfortable with. Same is the case with religions. The same way any operating system has  bugs and  developers, religions too appear to have their own idiosyncrasies and evolve over time.

#Atheists are of two kinds. The first kind of Atheists are those kind of developers who develop their own operating systems to suit to their specific needs. These are the real kind of Atheists as they believe that the existing operating systems don’t satisfy their needs so they build their own. The second type of Atheists are  those who know nothing about operating systems and are computer illiterates.The problem is with these kind of Atheists who advocate their senseless Atheism. The real Atheists are wise enough to understand that not every body will be able to develop a  new operating system and also most people are happy with the existing operating systems to satisfy their needs so they don’t bother about advocating their Atheism. So teach your kids the righteousness that religion has got to offer. Don’t make to grow them as Atheists. If they happen to be so they will evolve so.

#An artist should not be driven by the necessity to impress anyone else in this world. He should let his imagination flow and produce work that impresses him the most. He should take pride in being completely himself. He should believe that he is a class of his own. Then only shall the greatest pieces of art be produced.

#There is something good about being sad, gloomy and dejected sometimes. It makes you feel down to earth and makes you think as a very simple human being with no friendships and money who tries to survive every single day. These moments help you discover  more of you.


Q. I don’t know much about skateboards. What are they?
A. Well, skateboards  are basically boards with wheels that you can ride on. This is how a  typical skateboard looks like.

Q.Who uses skateboards? Where is it popular?
A. Skateboarding is mostly popular among the youth  and teenagers.  It is  majorly popular in  United states and Europe.

Q.What is the difference between longboard and skateboard?
A.Longboard has bigger wheels and a bigger board so it is stable and easy to ride long distances. Skateboards are usually used for performing tricks   and are easier to carry as they weigh less when compared to Longboards. Longboards too have their own set of tricks that can be done on them.   This is the longboard that I  currently use.

Q.What is the price range of skateboards and longboards?
A. Skateboards  are relatively cheaper when compared to longboards. The prices of skateboards are typically  between $20 – $150 whereas longboards range between $60-$320.  You would get a decent skateboard for $50 and a decent longboard for $120.

Q. What are the things required for Skateboarding as a sport?
A. Skateboard, Shoes, Helmet,Knee and elbow pads, tools to tighten or loosen the skateboard/longboard are the basic equipment needed. Optionally you may get sliding gloves and skateboarding ramp too.

Q. What do I start with? Skateboard or Longboard?
A. I would advice you to start on a mid range longboard as it is cheaper and stable for beginners. You can move on to a better longboard once you get basic riding skills or buy a good skateboard if you want to practise some tricks.The first thing is to find your balance on the board. Although it takes a while it isn’t hard with some days of practise.

Q.How do they perform tricks with Skateboards?                                                                                  A. All the tricks are done just by taking advantage of the shape of the skateboard(nose and tail). They don’t require anything else other than just a normal skateboard .Tricks can only be done once you get good mastery of skateboard riding. The following video gives a very neat introduction to beginner skateboarding and tricks.

Similar fun riding Stuff

Unicycle

Unicycle is a single tire with pedals attached to it. Unicycling is not as popular as Skateboarding but you can find Unicyclists once in a while near parks etc. A unicycle typically costs about $100-120. Watch the following cool Unicycling tricks video.

Heely

Heelys are shoes with wheels at the heel side. Heelys are generally used by kids and are fun to ride. Though the heel side has wheels you can use them and walk normally when you want to. Usually Heelys come in the price range of $40-100 Watch the following tutorial to get you started with Heelys.

Caster Board [RipStik/WaveBoard]

Caster Board is a two-wheeled vehicle that is closely related to the skateboard. The major advantage with this is  that  you need not step off the board and push it like a skateboard or longboard. You can propel this board by sideways movement just by being on the board.You would get a decent Caster Board for about 40$. Watch the following video to know how to ride Caster Board.

SkateCycle

SkateCycle is a self propelled skate that doesn’t have a hub(center part of wheel). It is driven with a similar mechanism as Caster Board and has the look of a miniature  cycle. It costs 150$ and it is an award winning design by http://www.brooklynworkshop.com/ . Watch the following video to get an idea of  skateCycle riding.

Scooter

Scooter is very popular among school age kids and teenagers. It is relatively easier to ride when compared to skateboards. You can get a good Scooter for about $60. It is easily foldable so you can carry it in hand whenever you want to.


Three Wheeled Scooter

Three wheeled scooter is a chainless, pedal less device that can be rode by leaning to right and left alternatively without ever touching foot to the ground.  A typical three wheeled scooter ranges from $150 – $400 depending on the size and make quality. Watch the following video to understand the riding mechanism better.

 

Inline Skates[Roller Blades]

Inline skates are shoes with wheels attached to each pair. They have two, three, four, or five wheels arranged in a single line. Some of them have a heel stop to slow down while skating. You can get a good pair of roller blades for about $80.

So, that ends my small description of different kinds of riding stuff .  I believe rest of them are variants of the ones described here. However excuse me if I seemed to have  missed any important ones along the way.

Previously, when we visit a new place it was completely about we enjoying the warmth of it…Now, all of our time is lost in figuring out spots to take cool pics and post them on Facebook… We enjoy just a little and the remaining time is lost in giving an impression to others that we enjoyed a lot …

I close my eyes and go back in time. December is the time of the year when I used to get back from school very enthusiastically to fly kites. The evening sky used to be very colorful with kites all around and the music of the birds returning to their homes. The gang rivalry in running after cut kites , selling the cut kites to other kids saying that the kite belongs to some legendry kite flyer, gossips about the special manja (kite flying thread) brought from Mumbai, I miss all that fun. Ever since I learnt kite flying I have always been flying kites this season but this December doesn’t seem to be the same. The evening sky is still the same except that it is replaced with flying machines connecting busy people in this busy world. Well, we gotta move on !!!

The most beautiful things in this world for you are not popular out  there to experience them in one go. You have to explore and experience them. Perhaps that is the majesty of life , savoring each single moment as you unravel the beauty that moment withholds until you come across it. I’ve recently come across this video where two tourists come across a spectacular phenomenon – murmuration( a flock of starlings). You  have to watch the video to know what I am talking about.

.

Their work looks pretty impressive. You can also take a look at their website. http://www.islandsandrivers.co.uk/portfolio.html

These busy roads, rushing crowd just daze me. Most of them rush without having even the slightest idea about where they are headed. Hold on , there is nothing spectacular on the way ahead, it is all about enjoying and savoring the present moment in life.

I’ve got a thing to say about artists.  An artist should not be driven by the necessity to impress anyone else in this world. He should let his imagination flow and produce work that impresses him the most. He should take pride in being completely himself. He should believe that he is a class of his own. Then only shall the greatest pieces of art be produced. Here is one piece of music that I feel is sublime and ethereal.(The following one is a cover version)