Archive for September, 2011

Select and Move Objects/Points using OpenCV – Drag and Drop

If you have a passion in image processing and computer animations, this post will be interesting . This post explains how to use the  OpenCV to select and move the objects.

 Before the explanations, watch this video to get the idea.

As you can see, the controls are based on the mouse movements and clicks.

  • So first need to implement the mouse-handler that comes with OpenCV - cvSetMouseCallback
    • Left button down – select the object of clicked point - findImg( x, y)
    • Left button up – release the object if there any objects has been picked - releaseImg(selectedImg,x,y);
    • On mouse move – move the selected object with mouse
void mouseHandler(int event, int x, int y, int flags, void *param)
{

	switch(event) {
	case CV_EVENT_LBUTTONDOWN:		//left button press
		selectedImg=findImg( x, y);
		break;

	case CV_EVENT_LBUTTONUP:	//left mouse button release
		if((selectedImg!=NULL)&&point!=-1){
			releaseImg(selectedImg,x,y);
			selectedImg=NULL;
		}
		break;

	case CV_EVENT_MOUSEMOVE:
		/* draw a rectangle*/
		if(point!=-1){
			if(selectedImg!=NULL){
				temp = cvCloneImage(selectedImg);
				cvRectangle(temp,
					cvPoint(x - 1, y - 1),
					cvPoint(x + 1, y + 1),
					cvScalar(0, 0,  255,0), 2, 8, 0);

				//adjust the lines
				for(int i=0;i<nop;i++){
					if(i!=point){
						cvLine(temp,
							cvPoint(x,y ),
							cvPoint(globalCoordinateX[i] , globalCoordinateY[i] ),
							cvScalar(0, 0,  255,0), 1,8,0);
					}
				}
				cvShowImage("Drag & Drop", temp);
			}
			break;
		}
		cvReleaseImage(&temp);
	}
}
  • Then implement the logics for the findImg( x, y) & releaseImg(selectedImg,x,y)  methods according to your requirements.
    •  Here i used an integer array to store the initial position of each object.
    • Then search for object using the x & y coordinates when there is a click.
    • when releasing the object update the integer array with released coordinate.
  • Finally call the cvSetMouseCallback( “Drag & Drop”, mouseHandler, NULL ) to activate the mouse handler to the window. where;
    • “Drag & Drop” – the OpenCV window name
    • mouseHandler – the mouse handler function name.
Check the links for demo and source

Happy reading and animation  :) .

, , , ,

Leave a Comment

Tips for creating posters using MS Word

This post talks about, “Tips for create posters using Microsoft Word” if you don’t have any experiences with other tools like Photoshop or Gimp.

Word 2007/2010 improved a lot compare to its previous releases. Here I share some of the features that I know . . .

  • First setup the poster format.
  • Used text boxes to write texts. Text box has the feature of adding backgrounds and nice borders that make more attractive the poster.
    • Especially when describing project components use text box.
  • Use some nice picture for the background.
  • Use the picture styles.
  • Use MS Word Illustrations whenever needed.
Recently i experienced with creating a poster for my final year project. Initially I started with some

 graphic editing tool and faced a hard time to make the poster within a limited time :) . Suddenly got a thought of “Why don’t I work with the tool that I used for documentation”….  yap, that led me to pick MS word even i never used it to graphic editing purposes.

Happy Poster :)

,

1 Comment

Follow

Get every new post delivered to your Inbox.

Join 91 other followers