Spot the Difference Game

1 minute read

Overview

  • Term project in Embedded Vision course (Undergraduate)
  • Application of Image Processing with using OpenCV
  • If you want more information about its source code, visit my Github

Idea

  • For easy control, this program is based on mouse-click actions
  • Contours detection is the main function in this program process

Description

  • Have 3 levels of difficulty, Hard-Normal-Easy
  • Time limit is depend on the level of difficulty
  • Contours Detection
    • Use 3 OpenCV methods
      • cvAbsDiff()
      • cvFindContours()
      • cvDrawContours()
    • More information about these 3 methods, refer some documentation sites

cvAbsDiff()

  • Format
    • cvAbsDiff(CvArr* src1, CvArr* src2, CvArr* dst)
  • Function
    • Solve the absolute value from the difference between src1 and src2 (matrix form)
    • Put the solved absolute value in dst variable
    • For this program, this method solves the difference value between original image and manipulated image

cvFindContours()

  • Format
    • cvFindContours(CvArr* image, CvMemStorage* storage, CvSeq** firstContour, int headerSize = sizeof(CvContour), int mode = CV_RETR_LIST, int method = CV_CHAIN_APPROX_SIMPLE, CvPoint offset = cvPoint(0,0))
  • Function
    • Find the number of contours in binary image (Convert from input image)
    • Return variable (sequence), firstContour is the outermost contour
    • For this program, this method solves the contours from the result image of cvAbsDiff() method
  • Parameters
    • image
      • Input image (original), must be 8-bit single channel image(Binary Image)
    • storage
      • Memory that searched contours are saved in
    • firstContour
      • The pointer of the outermost contour
    • headerSize
      • Size of Sequence Header
    • mode
      • CV_RETR_EXTERNAL
      • CV_RETR_LIST
      • CV_RETR_CCOMP
      • CV_RETR_TREE
    • method
      • CV_CHAIN_CODE
      • CV_CHAIN_APPROX_NONE
      • CV_CHAIN_APPROX_SIMPLE
      • CV_CHAIN_APPROX_TC89_L1, CV_CHAIN_APPROX_TC89_KCOS
      • CV_LINK_RUNS
    • offset

cvDrawContours()

  • Format
    • cvDrawContours(CvArr* img, CvSeq* contour, CvScalar external_color, CvScalar hole_color, int max_level, int thickness = 1, int lineType = 8)
  • Function
    • Draw the contours from CvSeq* contour
    • Differentiate exterior or hole before drawing
    • For this program, this method draws the contours from the result of cvFindContours() method
  • Parameters
    • image
    • contour
      • Contours information from cvFindContours() method
    • external_color
    • hole_color
    • max_level
    • thickness
    • lineType

Result

  • Game start & Setting levels difficulty

    Game start screen
    Game Start
    Level difficulty
    Level difficulty
  • Game play screen

    Game play-inital
    Game Play - Inital mode
    Game play-run
    Game Play - Running mode
  • Game clear & over

    Game Clear
    Game Clear
    Game Over
    Game Over

Development Environment

  • Visual Studio 2017 (C++ language)
  • OpenCV

Reference

Leave a comment