Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Trouble detecting hand drawn shapes

I have written a basic code to detect hand drawn shapes i.e. drawn on paper and captured with a camera.[p1.png] and this is the output that i am getting.(/upfiles/14671047931550092.png)(/upfiles/14671046845890363.png)

import numpy as np
import cv2

im = cv2.imread('c:/p1.png')
cv2.imshow('original image',im)
cv2.waitKey()

imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
cv2.imshow('gray image',imgray)
cv2.waitKey()

ret,thresh = cv2.threshold(imgray,80,255,0)
cv2.imshow('thresh image',thresh)
cv2.waitKey()

image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.imshow('cont image',image)
cv2.waitKey()
ctt=0
for cnt in contours:
     approx = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)
print len(approx)
if len(approx)==5:
    print "pentagon"
    cv2.drawContours(im,[cnt],0,255,-1)
    ctt+=1
elif len(approx)==3:
    print "triangle"
    cv2.drawContours(im,[cnt],0,(0,255,0),-1)
    ctt+=1
elif len(approx)==4:
    print "square"
    cv2.drawContours(im,[cnt],0,(0,0,255),-1)
    ctt+=1
elif len(approx) == 9:
    print "half-circle"
    cv2.drawContours(im,[cnt],0,(255,255,0),-1)
    ctt+=1
elif len(approx) > 15:
    print "circle"
    cv2.drawContours(im,[cnt],0,(0,255,255),-1)
    ctt+=1

cv2.imshow('img',im)
cv2.waitKey(0)
cv2.destroyAllWindows()
print "Total no.= ",ctt
click to hide/show revision 2
No.2 Revision

updated 2016-06-28 04:19:43 -0500

berak gravatar image

Trouble detecting hand drawn shapes

I have written a basic code to detect hand drawn shapes i.e. drawn on paper and captured with a camera.[p1.png] and this is the output that i am getting.(/upfiles/14671047931550092.png)(/upfiles/14671046845890363.png)getting.

import numpy as np
import cv2

im = cv2.imread('c:/p1.png')
cv2.imshow('original image',im)
cv2.waitKey()

imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
cv2.imshow('gray image',imgray)
cv2.waitKey()

ret,thresh = cv2.threshold(imgray,80,255,0)
cv2.imshow('thresh image',thresh)
cv2.waitKey()

image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.imshow('cont image',image)
cv2.waitKey()
ctt=0
for cnt in contours:
     approx = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)
print len(approx)
if len(approx)==5:
    print "pentagon"
    cv2.drawContours(im,[cnt],0,255,-1)
    ctt+=1
elif len(approx)==3:
    print "triangle"
    cv2.drawContours(im,[cnt],0,(0,255,0),-1)
    ctt+=1
elif len(approx)==4:
    print "square"
    cv2.drawContours(im,[cnt],0,(0,0,255),-1)
    ctt+=1
elif len(approx) == 9:
    print "half-circle"
    cv2.drawContours(im,[cnt],0,(255,255,0),-1)
    ctt+=1
elif len(approx) > 15:
    print "circle"
    cv2.drawContours(im,[cnt],0,(0,255,255),-1)
    ctt+=1

cv2.imshow('img',im)
cv2.waitKey(0)
cv2.destroyAllWindows()
print "Total no.= ",ctt

Trouble detecting hand drawn shapes

I have written a basic code to detect hand drawn shapes i.e. drawn on paper and captured with a camera.[p1.png] and this is the output that i am getting.

import numpy as np
import cv2

im = cv2.imread('c:/p1.png')
cv2.imshow('original image',im)
cv2.waitKey()

imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
cv2.imshow('gray image',imgray)
cv2.waitKey()

ret,thresh = cv2.threshold(imgray,80,255,0)
cv2.imshow('thresh image',thresh)
cv2.waitKey()

image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.imshow('cont image',image)
cv2.waitKey()
ctt=0
for cnt in contours:
     approx = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)
 print len(approx)
 if len(approx)==5:
     print "pentagon"
     cv2.drawContours(im,[cnt],0,255,-1)
    ctt+=1
     ctt+=1
     elif len(approx)==3:
     print "triangle"
     cv2.drawContours(im,[cnt],0,(0,255,0),-1)
    ctt+=1
     ctt+=1
     elif len(approx)==4:
     print "square"
     cv2.drawContours(im,[cnt],0,(0,0,255),-1)
    ctt+=1
     ctt+=1
     elif len(approx) == 9:
     print "half-circle"
     cv2.drawContours(im,[cnt],0,(255,255,0),-1)
    ctt+=1
     ctt+=1
     elif len(approx) > 15:
     print "circle"
     cv2.drawContours(im,[cnt],0,(0,255,255),-1)
     ctt+=1

cv2.imshow('img',im)
cv2.waitKey(0)
cv2.destroyAllWindows()
print "Total no.= ",ctt