Object Move Controlling in Game Implementation Using OpenCV

Similar documents
An Implementation on Object Move Detection Using OpenCV

Building Detection. Guillem Pratx LIAMA. 18 August BACKGROUND 2 2. IDEA 2

University of Cambridge Engineering Part IIB Module 4F12 - Computer Vision and Robotics Mobile Computer Vision

Edge and corner detection

CS4670: Computer Vision

Analysis of Image and Video Using Color, Texture and Shape Features for Object Identification

Laboratory of Applied Robotics

ECE 172A: Introduction to Intelligent Systems: Machine Vision, Fall Midterm Examination

Last update: May 4, Vision. CMSC 421: Chapter 24. CMSC 421: Chapter 24 1

Leow Wee Kheng CS4243 Computer Vision and Pattern Recognition. Motion Tracking. CS4243 Motion Tracking 1

BSB663 Image Processing Pinar Duygulu. Slides are adapted from Selim Aksoy

SUMMARY: DISTINCTIVE IMAGE FEATURES FROM SCALE- INVARIANT KEYPOINTS

The NAO Robot, a case of study Robotics Franchi Alessio Mauro

Local Feature Detectors

Image Processing

EXAM SOLUTIONS. Image Processing and Computer Vision Course 2D1421 Monday, 13 th of March 2006,

Biometrics Technology: Image Processing & Pattern Recognition (by Dr. Dickson Tong)

Local Image preprocessing (cont d)

[ ] Review. Edges and Binary Images. Edge detection. Derivative of Gaussian filter. Image gradient. Tuesday, Sept 16

Computer and Machine Vision

Complex Sensors: Cameras, Visual Sensing. The Robotics Primer (Ch. 9) ECE 497: Introduction to Mobile Robotics -Visual Sensors

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

CS4495/6495 Introduction to Computer Vision

CS5670: Computer Vision

Case Study: Attempts at Parametric Reduction

Scene Text Detection Using Machine Learning Classifiers

CSE152 Introduction to Computer Vision Assignment 3 (SP15) Instructor: Ben Ochoa Maximum Points : 85 Deadline : 11:59 p.m., Friday, 29-May-2015

Robotics Programming Laboratory

Mobile Human Detection Systems based on Sliding Windows Approach-A Review

Object Recognition Tools for Educational Robots

Local features: detection and description. Local invariant features

Final Exam Study Guide

Harder case. Image matching. Even harder case. Harder still? by Diva Sian. by swashford

Computer Science Faculty, Bandar Lampung University, Bandar Lampung, Indonesia

Advanced Video Content Analysis and Video Compression (5LSH0), Module 4

Crush Around Augmented Reality Game Computer Vision and Image Processing for Mobile Platforms

Image Processing (1) Basic Concepts and Introduction of OpenCV

Final Review CMSC 733 Fall 2014

PERFORMANCE CAPTURE FROM SPARSE MULTI-VIEW VIDEO

Digital Images. Kyungim Baek. Department of Information and Computer Sciences. ICS 101 (November 1, 2016) Digital Images 1

EECS150 - Digital Design Lecture 14 FIFO 2 and SIFT. Recap and Outline

Computer Vision. Recap: Smoothing with a Gaussian. Recap: Effect of σ on derivatives. Computer Science Tripos Part II. Dr Christopher Town

REAL-TIME PATTERN RECOGNITION

Edge detection. Goal: Identify sudden. an image. Ideal: artist s line drawing. object-level knowledge)

Lecture 6: Edge Detection

Progress Report of Final Year Project

Face and Nose Detection in Digital Images using Local Binary Patterns

Active Stereo Vision. COMP 4900D Winter 2012 Gerhard Roth

FPGA IMPLEMENTATION FOR REAL TIME SOBEL EDGE DETECTOR BLOCK USING 3-LINE BUFFERS

Edge Detection. Today s reading. Cipolla & Gee on edge detection (available online) From Sandlot Science

Harder case. Image matching. Even harder case. Harder still? by Diva Sian. by swashford

(Sample) Final Exam with brief answers

Image matching. Announcements. Harder case. Even harder case. Project 1 Out today Help session at the end of class. by Diva Sian.

CS4495 Fall 2014 Computer Vision Problem Set 5: Optic Flow

CS 378: Autonomous Intelligent Robotics. Instructor: Jivko Sinapov

Multimedia Technology CHAPTER 4. Video and Animation

Edges and Binary Images

LUMS Mine Detector Project

Practice Exam Sample Solutions

Digital Image Processing COSC 6380/4393

Features Points. Andrea Torsello DAIS Università Ca Foscari via Torino 155, Mestre (VE)

A Comparison of SIFT and SURF

CHAPTER 1 Introduction 1. CHAPTER 2 Images, Sampling and Frequency Domain Processing 37

Anno accademico 2006/2007. Davide Migliore

Introduction to Computer Vision

Character Recognition from Google Street View Images

The SIFT (Scale Invariant Feature

A Vision System for Automatic State Determination of Grid Based Board Games

Effects Of Shadow On Canny Edge Detection through a camera

Tracking facial features using low resolution and low fps cameras under variable light conditions

Tangents. In this tutorial we are going to take a look at how tangents can affect an animation.

CS223b Midterm Exam, Computer Vision. Monday February 25th, Winter 2008, Prof. Jana Kosecka

Image Processing: Final Exam November 10, :30 10:30

Multimedia Retrieval Exercise Course 2 Basic of Image Processing by OpenCV

Nonlinear State Estimation for Robotics and Computer Vision Applications: An Overview

Sobel Edge Detection Algorithm

Outline 7/2/201011/6/

Image processing and features

Solution: filter the image, then subsample F 1 F 2. subsample blur subsample. blur

Introduction to Computer Graphics and Computer Vision Assignment 3: Due 7/27/2015

HISTOGRAMS OF ORIENTATIO N GRADIENTS

6. Applications - Text recognition in videos - Semantic video analysis

Edge detection. Winter in Kraków photographed by Marcin Ryczek

Feature descriptors and matching

Fundamentals of Stereo Vision Michael Bleyer LVA Stereo Vision

MATRIX BASED INDEXING TECHNIQUE FOR VIDEO DATA

Cs : Computer Vision Final Project Report

Object Recognition Algorithms for Computer Vision System: A Survey

Interactive Virtual Environments

Introduction to Medical Imaging (5XSA0)

MET71 COMPUTER AIDED DESIGN

Exploring Projectile Motion with Interactive Physics

Edge and Texture. CS 554 Computer Vision Pinar Duygulu Bilkent University

Cross-platform Mobile Document Scanner

Robert Collins CSE598G. Intro to Template Matching and the Lucas-Kanade Method

Chapter 3 Image Registration. Chapter 3 Image Registration

Local Features: Detection, Description & Matching

DIGITAL IMAGE PROCESSING

Digital Image Processing. Image Enhancement - Filtering

Shadows in the graphics pipeline

Transcription:

Object Move Controlling in Game Implementation Using OpenCV Professor: Dr. Ali Arya Reported by: Farzin Farhadi-Niaki Lindsay Coderre Department of Systems and Computer Engineering Carleton University Ottawa, Canada I. INTRODUCTION Computer vision is a rapidly growing field, partly as a result of both cheaper and more capable cameras, partly because of affordable processing power, and partly because vision algorithms are starting to mature. OpenCV itself has played a role in the growth of computer vision by enabling thousands of people to do more productive work in vision. With its focus on real-time vision, OpenCV helps students and professionals efficiently implement projects and jump-start research by providing them with a computer vision and machine learning infrastructure that was previously available only in a few mature research labs. II. METHODOLOGY Computer vision is the transformation of data from a still or video camera into either a decision or a new representation. All such transformations are done for achieving some particular goal. The input data may include some contextual information such as "the camera is mounted in a car" or "laser range finder indicates an object is 1 meter away". The decision might be "there is a person in this scene" or "there are 14 tumour cells on this slide". A new representation might mean turning a color image into a grayscale image or removing camera motion from an image sequence. For robotics, we need object recognition (what) and object location (where): a) Object recognition In OpenCV, there are a wide range of approaches to detect an object; the techniques such as: convolution/filters, thresholds, histogram and matching, contours, efficient nearest neighbour matching to recognize objects using huge learned databases of objects, etc. b) Object location Again, in OpenCV, there are various techniques for finding the object location, e.g. background subtraction (to find the moving objects), corner finding, optical flow, mean-shift and camshaft tracking, structure from motion using SIFT descriptor and SURF gradient histogram grids, or just simply finding the edge of the object and momentarily checking the location of object s centre on pixel by pixel based movement. A. Convolution Convolution is the basis of many of the transformations. In the abstract, this term means something we do to every part of an image. What a particular convolution "does" is determined by the form of the Convolution kernel being used. This kernel is essentially just a fixed size array of numerical coefficients along with an anchor point in that array, which is typically located at the center. The size of the array is called the support of the kernel.

We can express this procedure in the form of an equation. If we define the image to be I(x, y), the kernel to be G(i, j) (where 0 < i < M i 1 and 0 < j < M j 1), and the anchor point to be located at (a i, a j ) in the coordinates of the kernel, then the convolution H(x, y) is defined by the following expression: B. Canny The most significant new dimension to the Canny algorithm is that it tries to assemble the individual edge candidate pixels into contours. These contours are formed by applying a hysteresis threshold to the pixels. This means that there are two thresholds, an upper and a lower. If a pixel has a gradient larger than the upper threshold, then it is accepted as an edge pixel; if a pixel is below the lower threshold, it is rejected. If the pixel's gradient is between the thresholds, then it will be accepted only if it is connected to a pixel that is above the high threshold. void cvcanny( const CvArr* img, CvArr* edges, double lowthresh, double highthresh, int aperturesize = 3 ); The cvcanny() function expects an input image, which must be grayscale, and an output image, which must also be grayscale. C. Threshold double cvthreshold( CvArr* src, CvArr* dst, double threshold, double max_value, int threshold_type ); Frequently we have done many layers of processing steps and want either to make a final decision about the pixels in an image or to categorically reject those pixels below or above some value while keeping the others. The OpenCV function cvthreshold() accomplishes these tasks. The basic idea is that an array is given, along with a threshold, and then something happens to every element of the array depending on whether it is below or above the threshold. The cvthreshold() function handles only 8-bit or floating-point grayscale source images. CV_THRESH_BINARY_INV dst i = (src i > T)? M : 0

Fig 1. Each threshold type corresponds to a particular comparison operation between the i th source pixel (src i) and the threshold (denoted in the table by T). Depending on the relationship between the source pixel and the threshold, the destination pixel dst i may be set to 0, the src i, or the max_value (denoted in the table by M). D. Adaptive Threshold There is a modified threshold technique in which the threshold level is itself variable. In OpenCV, this method is implemented in the cvadaptivethreshold() function: void cvadaptivethreshold( CvArr* src, CvArr* dst, double max_val, int adaptive_method = CV_ADAPTIVE_THRESH_MEAN_C int threshold_type = CV_THRESH_BINARY, int block_size = 3, double param1 = 5 ); cvadaptivethreshold() allows for two different adaptive threshold types depending on the settings of adaptive_method. In both cases the adaptive threshold T(x, y) is set on a pixel-by-pixel basis by computing a weighted average of the b-by-b region around each pixel location minus a constant, where b is given by block_size and the constant is given by param1. If the method is set to CV_ADAPTIVE_THRESH_MEAN_C, then all pixels in the area are weighted equally. If it is set to CV_ADAPTIVE_THRESH_GAUSSIAN_C, then the pixels in the region around (x, y) are weighted according to a Gaussian function of their distance from that center point. The adaptive threshold technique is useful when there are strong illumination or reflectance gradients that you need to threshold relative to the general intensity gradient. This function handles only singlechannel 8-bit or floating-point images, and it requires that the source and destination images be distinct.

Fig 2. Binary threshold versus adaptive binary threshold: the input image (top) was turned into a binary image using a global threshold (lower left) and an adaptive threshold (lower right); raw image courtesy of Kurt Konolidge E. Contours Although algorithms like the Canny edge detector can be used to find the edge pixels that separate different segments in an image, they do not tell us anything about those edges as entities in themselves. The next step is to be able to assemble those edge pixels into contours. cvfindcontours()is a convenient function in OpenCV that will do exactly this for us. Specifically, with assigning memory storages, OpenCV functions gain access to memory when they need to construct new objects dynamically; then we will need to use sequences (as something similar to the generic container classes), which are the objects used to represent contours generally. With those concepts in hand, we will get into contour finding. A contour is a list of points that represent a curve in an image. Contours are represented in OpenCV by sequences in which every entry in the sequence encodes information about the location of the next point on the curve. The function cvfindcontours() computes contours from binary images. It can take images created by cvcanny(), which have edge pixels in them, or images created by functions like cvthreshold() or cvadaptivethreshold(), in which the edges are implicit as boundaries between positive and negative regions. Drawing a contour on the screen using cvdrawcontours() function is the next step. Here we create a window with an image in it. A trackbar sets a simple threshold, and the contours in the thresholded image are drawn. The image is updated whenever the trackbar is adjusted. III. DISCUSSIONS OpenCV, short for Open Computer Vision, is used in the purpose of our project so that movement captured from the camera is translated into movement of objects within the game interface. A basic framework is used as the foundation to create any simple game interface. In terms of code, there are three classes created: Camera, game and object contain all of the basic functions that all games require.

A. Camera Class In this project, using OpenCV, we have tried to implement a simulation of object move detection (Fig. 3) where would be used in game control. Fig 3. The camera result (including four windows). The procedure of requirements for this implementation through Camera class has the following steps: 1) Capturing the image as a frame from a camera. 2) Converting the image/frame to 8-bits grayscale image to be compatibly usable in some filters like Canny. 3) Creating trackbars for up and down thresholds (Fig. 4). Fig 4. Trackbars for up and down thresholds. 4) Finding the edge of the object using Canny or Threshold (Adaptive Threshold) functions (Fig. 5).

Fig 5. Edge of the object. 5) Creating dynamic structure and sequence for the contours, and finding the current location (x, y) of the object s centre after finding its contours. 6) Finally, transferring the objects location (x, y) to the Game class to control the objects movements on the screen. B. Object Class The Object class fundamentally contains the functions to draw a box and a circle. Both of these functions have variables to describe its size, position and colour. Depending on the game, certain other variables and functions are added, such as velocity, if the object is continually moving around the game, or detectcollision() if the object is going to interact with other objects. void Object::drawCircle( CvArr* dst, int centerx, int centery, int radius, int b, int g, int r ) { cvcircle( dst, cvpoint( centerx, centery ), radius, cvscalar( b, g, r ), -1 ); } C. Game Class The Game class contains all of the game logics. It initializes all of the objects and the camera. It creates the game interface window and draws the scene. Any other game properties can also be added, such as a score or a function to continually animate an object around the screen. Two of the more important functions are the movement functions. They describe how the objects move will be controlled by the users, whether in every direction or only vertically or horizontally. These functions use the u and v values that are outputted from the Camera class, where u and v will become the x and y positions of the object designated. IV. RESULTS To explore the possibilities of this framework, some games were developed.

A. Pong Pong was first created to explore the classes (Fig. 6). Two paddles are controlled by the user to hit a ball back and forth. It also keeps score of how many times a paddle lets the ball past. Some extra functions were added. For example, the ball has a spin when it hits a paddle. Depending on where the ball hits, the y velocity of the ball increases or decreases. void spinball( Object paddle ) { int balllocation; float ballpercent; } balllocation = ball.cy - paddle.y; ballpercent = (float)balllocation/(float)paddle.height; ballpercent = ballpercent*10; ball.yvel = (int)(ballpercent + 0.5); Fig 6. Pong game result. B. Maze Another game created was a Maze (Fig. 7). A ball moves within a path. The background image of the path is analyzed and the colour value is stored in a matrix. Before the ball moves, it evaluates the wanted destination based on the u and v values from the camera. If the value in the matrix indicates that the colour is not black, the ball moves to the new location. This way the ball can only travel on the path. Setting the Matrix: for( int i=0; i < bg->width; i++ ) for( int j=0; j < bg->height; j++ ) { CvScalar pixelvalue = cvget2d( bg, j, i ); cvmset( matrix, i, j, pixelvalue.val[0] ); }

Fig 7. Maze game result. C. Third Game There are endless possibilities for simple games using this framework. A ball could collect boxes by adding detectcollision() for each box and a visibility Boolean that determines whether the box is on screen after it collides with the ball (Fig. 8). A breakaway game could be made using an animated ball, a paddle with a horizontal spin function and a bunch of boxes with the detectcollision() and visibility Boolean combination. Game logics for individual games can be made into its own class and members can be added to the Object class to make the game as optimal as possible. Fig 8. Third game result.

V. CONCLUSION Computer vision applications are growing rapidly, from product inspection to image and video indexing on the Web to medical applications and even to local navigation on Mars. OpenCV is also growing to accommodate these developments. One of the key new development areas for OpenCV is robotic perception. This effort focuses on 3D perception as well as 2D plus 3D object recognition since the combination of data types makes for better features for use in object detection, segmentation and recognition. Robotic perception relies heavily on 3D sensing, so efforts are under way to extend camera calibration, rectification and correspondence to multiple cameras and to camera plus laser rangefinder combinations. Creating capable robots subsumes most fields of computer vision and artificial intelligence, from accurate 3D reconstruction to tracking, identifying humans, object recognition, and image stitching and on to learning, control, planning, and decision making. Any higher-level task, such as planning, is made much easier by rapid and accurate depth perception and recognition. It is in these areas especially that OpenCV hopes to enable rapid advance by encouraging many groups to contribute and use ever better methods to solve the difficult problems of real-world perception, recognition, and learning. OpenCV will, of course, support many other areas as well, from image and movie indexing on the web to security systems and medical analysis. The wishes of the general community will heavily influence OpenCV's direction and growth. There is a worldwide community of interactive artists who use OpenCV so that viewers can interact with their art in dynamic ways. The most commonly used routines for this application are face detection, optical flow, and tracking. The focused effort on improving object recognition will allow different modes of interacting with art, because objects can then be used as modal controls. With the ability to capture 3D meshes, it may also be possible to "import" the viewer into the art and so allow the artist to gain a better feel for recognizing user action; this, in turn, could be used to enhance dynamic interaction. The needs and desires of the artistic community for using computer vision will receive enhanced priority in OpenCV's future. A group of manufacturers are aiming to develop cell-phone projectors perfect for robots, because most cell phones are lightweight, low-energy devices whose circuits already include an embedded camera. This opens the way for close-range portable structured light and thereby accurate depth maps, which are just what we need for robot manipulation and 3D object scanning. Computer vision has a rich future ahead, and it seems likely to be one of the key enabling technologies for the 21st century. Likewise, OpenCV seems likely to be (at least in part) one of the key enabling technologies for computer vision. Endless opportunities for creativity and profound contribution lie ahead. REFERENCES [1] Bradski, G., Kaehler, A. 2008, Learning OpenCV: Computer Vision with the OpenCV Library. O Reilly Media Inc., Sebastopol, CA.