Skip to content

Commit

Permalink
Miscellaneous bug fixes and updates
Browse files Browse the repository at this point in the history
- Added if main statements to most class files
- Updated current test parser to be more efficient and to pull all
shapes out of a picture
- Updated parser; now pseudocode is complete, working on migrating that
to runnable code
  • Loading branch information
DarkmatterVale committed May 5, 2015
1 parent 4a82b8a commit 21f2d47
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 28 deletions.
5 changes: 4 additions & 1 deletion clear_unwanted_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ def empty_directory( directory_name, file_name ):
#if filename contains file_name:
if file_name in filename:
#delete filename
dirs.remove( file_name )
dirs.remove( file_name )

if __name__ == '__main__':
pass
5 changes: 4 additions & 1 deletion download_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ def download_most_recent_image():
if not stderr:
return true
else:
return false
return false

if __name__ == '__main__':
pass
5 changes: 4 additions & 1 deletion gpio_shooting.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ def get_shot_truefalse():
if GPIO.input( inPin ):
return true
else:
return false
return false

if __name__ == '__main__':
pass
21 changes: 13 additions & 8 deletions image_parser.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
__author__ = 'Vale Tolpegin'

class image_parser:
#image that needs to be parsed variable
import numpy as np
import cv2

class image_parser:
def __init__( self, *args, **kwargs ):
pass

def parse( picture_file ):
def parse( picture_file_name ):
#set image variable here with the image file picture_file

#find shapes in image ( basic geometric shapes such as circles, squares, triangles, etc )

#inside of those geometric shapes, find the number of different colors
#if there are 2 colors ( no more and no less )
#compare the ratio of those 2 colors
#if that ratio is close to 2:1 ( shape:letter )
#return true
#if there are 2 colors ( other than black, no more and no less )
#if there are 2 distinct seperate colors ( other than black ) within a couple of pixels of each other
#compare the ratio of those 2 colors ( non black )
#if that ratio is close to 2:1 ( shape:letter )
#return True

return false

#return false
if __name__ == '__main__':
pass
48 changes: 34 additions & 14 deletions image_testing.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,65 @@
import numpy as np
import cv2

img = cv2.imread( 'images/IMG_0116.jpg' )
img2 = cv2.imread( 'images/IMG_0116.jpg', 0 )
img = cv2.imread( 'images/IMG_0119.jpg' )
img2 = cv2.imread( 'images/IMG_0119.jpg', 0 )
ret,thresh = cv2.threshold(img2,127,255,0)
contours,h = cv2.findContours(thresh,1,2)

def img_copy( cnt ):
mask_img = np.zeros( img.shape, dtype=np.uint8 )
roi_corners = np.array( cnt, dtype=np.int32 )
black = (255, 255, 255)
cv2.drawContours( mask_img, [cnt], 0, black, -1 )

masked_img = cv2.bitwise_and( img, mask_img )

cv2.imshow( "Image", masked_img )
cv2.waitKey(0)
cv2.destroyAllWindows()

return test_image( masked_img )

def test_image( masked_img ):
return True

for cnt in contours:
approx = cv2.approxPolyDP(cnt,0.007*cv2.arcLength(cnt,True),True)

if cv2.contourArea(cnt) < 20000:
pass
else:
if len(approx)==9:
mask_img = np.zeros( img.shape, dtype=np.uint8 )
roi_corners = np.array( cnt, dtype=np.int32 )
white = (255, 255, 255)
cv2.drawContours( mask_img, [cnt], 0, white, -1 )

masked_img = cv2.bitwise_and( img, mask_img )

cv2.imshow( "Image", masked_img )
cv2.waitKey(0)
cv2.destroyAllWindows()

print len(approx)

if len(approx)==5:
print "pentagon"

img_copy( cnt )

cv2.drawContours(img,[cnt],0,255,-1)
elif len(approx)==3:
print "triangle"

img_copy( cnt )

cv2.drawContours(img,[cnt],0,(0,255,0),-1)
elif len(approx)==4:
print "square"

img_copy( cnt )

cv2.drawContours(img,[cnt],0,(0,0,255),-1)
elif len(approx)==5:
print "pentagon"

img_copy( cnt )

cv2.drawContours(img,[cnt],0,(0,0,127),-1)
elif len(approx) == 9:
print "complex"

img_copy( cnt )

cv2.drawContours(img,[cnt],0,(255,255,0),-1)

cv2.imshow( "Image", img )
Expand Down
9 changes: 6 additions & 3 deletions shoot_image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__author__ = 'Vale Tolpegin'

import os
import download_image from download_image
import download_image
import subprocess

class shoot_image:
Expand All @@ -23,5 +23,8 @@ def shoot_an_image():
download.download_most_recent_image()

return True
else
return False
else:
return False

if __name__ == '__main__':
pass

0 comments on commit 21f2d47

Please sign in to comment.