#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Th/u Sep 12 13:47:49 2019

@author: jiaxinsun
"""

from utility.image_processing import *
from utility.gesture import Gesture


acute_angle_count_to_gesture = [Gesture.rock, Gesture.scissor, Gesture.scissor, Gesture.unknown, Gesture.paper]


def detect_with_contours(roi):
    
    # detect gesture based on skin
    skin_img = detect_body_skin(roi)

    # get a list of contours for gesture
    contours = get_contours(skin_img) 
    
    if len(contours) > 0:
    
        # find the contour which have largest area in contour list
        largest_contour = get_largest_contour(contours) 
        
        # get a convex contour of hand
        hull = get_convex_hull(largest_contour)
        
        # get defects
        defects = cv2.convexityDefects(largest_contour, hull)

        # if defects exist, then get the number of defects 
        if defects is not None:
            
            defects_img, num_defects = get_defects_count(roi, largest_contour, defects)
        
            images = concatenate_images(skin_img, defects_img)
            
            # if the number of defects <5, return
            if num_defects < 5:
                
                return acute_angle_count_to_gesture[num_defects], images

    images = concatenate_images(skin_img, roi)
    return Gesture.unknown, images

1074674b6570e85cda1b862199f0a69ec717fd26
<mask token>

<mask token>


def detect_with_contours(roi):
    skin_img = detect_body_skin(roi)
    contours = get_contours(skin_img)
    if len(contours) > 0:
        largest_contour = get_largest_contour(contours)
        hull = get_convex_hull(largest_contour)
        defects = cv2.convexityDefects(largest_contour, hull)
        if defects is not None:
            defects_img, num_defects = get_defects_count(roi,
                largest_contour, defects)
            images = concatenate_images(skin_img, defects_img)
            if num_defects < 5:
                return acute_angle_count_to_gesture[num_defects], images
    images = concatenate_images(skin_img, roi)
    return Gesture.unknown, images

<mask token>
acute_angle_count_to_gesture = [Gesture.rock, Gesture.scissor, Gesture.
    scissor, Gesture.unknown, Gesture.paper]


def detect_with_contours(roi):
    skin_img = detect_body_skin(roi)
    contours = get_contours(skin_img)
    if len(contours) > 0:
        largest_contour = get_largest_contour(contours)
        hull = get_convex_hull(largest_contour)
        defects = cv2.convexityDefects(largest_contour, hull)
        if defects is not None:
            defects_img, num_defects = get_defects_count(roi,
                largest_contour, defects)
            images = concatenate_images(skin_img, defects_img)
            if num_defects < 5:
                return acute_angle_count_to_gesture[num_defects], images
    images = concatenate_images(skin_img, roi)
    return Gesture.unknown, images

<mask token>
from utility.image_processing import *
from utility.gesture import Gesture
acute_angle_count_to_gesture = [Gesture.rock, Gesture.scissor, Gesture.
    scissor, Gesture.unknown, Gesture.paper]


def detect_with_contours(roi):
    skin_img = detect_body_skin(roi)
    contours = get_contours(skin_img)
    if len(contours) > 0:
        largest_contour = get_largest_contour(contours)
        hull = get_convex_hull(largest_contour)
        defects = cv2.convexityDefects(largest_contour, hull)
        if defects is not None:
            defects_img, num_defects = get_defects_count(roi,
                largest_contour, defects)
            images = concatenate_images(skin_img, defects_img)
            if num_defects < 5:
                return acute_angle_count_to_gesture[num_defects], images
    images = concatenate_images(skin_img, roi)
    return Gesture.unknown, images

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Th/u Sep 12 13:47:49 2019

@author: jiaxinsun
"""

from utility.image_processing import *
from utility.gesture import Gesture


acute_angle_count_to_gesture = [Gesture.rock, Gesture.scissor, Gesture.scissor, Gesture.unknown, Gesture.paper]


def detect_with_contours(roi):
    
    # detect gesture based on skin
    skin_img = detect_body_skin(roi)

    # get a list of contours for gesture
    contours = get_contours(skin_img) 
    
    if len(contours) > 0:
    
        # find the contour which have largest area in contour list
        largest_contour = get_largest_contour(contours) 
        
        # get a convex contour of hand
        hull = get_convex_hull(largest_contour)
        
        # get defects
        defects = cv2.convexityDefects(largest_contour, hull)

        # if defects exist, then get the number of defects 
        if defects is not None:
            
            defects_img, num_defects = get_defects_count(roi, largest_contour, defects)
        
            images = concatenate_images(skin_img, defects_img)
            
            # if the number of defects <5, return
            if num_defects < 5:
                
                return acute_angle_count_to_gesture[num_defects], images

    images = concatenate_images(skin_img, roi)
    return Gesture.unknown, images
