Skip to content

Commit

Permalink
Merge pull request #5 from Anirudh-C/dfa-shape-detection
Browse files Browse the repository at this point in the history
Dfa shape detection
  • Loading branch information
shreyakupadhyay authored May 16, 2018
2 parents 7ca18d7 + 803fa93 commit f485481
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 0 deletions.
Empty file added DFA/__init__.py
Empty file.
Empty file added DFA/shapes/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions DFA/shapes/circle_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Circle Detection

import cv2
import sys
import numpy as np

def DetectCircles(image):
minpercent = 0.13
maxpercent = 0.33
height,width = image.shape[:2]
minValue = min(height,width)
maxValue = max(height,width)
min_radius = int(minpercent * minValue/2)
max_radius = int(maxpercent * maxValue/2)
houghcircles = cv2.HoughCircles(image, cv2.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=min_radius,maxRadius=max_radius)
houghcircles = np.uint16(np.around(houghcircles))
return houghcircles

def test():
img = cv2.imread(sys.argv[1],0)
for i in DetectCircles(img)[0,:]:
cv2.circle(img,(i[0],i[1]),i[2],(0,255,0),2)
cv2.circle(img,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

if __name__ == "__main__":
test()
70 changes: 70 additions & 0 deletions circle_detection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Circle Detection Module:

To run the circle detection module,

```bash
python DFA/shapes/circle_detection.py /path/to/image
```

**_Note_** : opencv, numpy are dependencies
## Some sample runs:

1. Perfect test case:

test/test1.png

![screenshot 1][test1]

Here the circles are detected almost perfectly. But the accept state is not detected as 2 circles,
because the circles are so close to each other.

2. Semi-perfect test case:

test/test2.png

![screenshot 2][test2]

test/test3.png

![screenshot 3][test3]

test/test4.png

![screenshot 4][test4]

test/test5.png

![screenshot 5][test5]

Here the states are all detected normally (except the accept state). But beyond a certain increase in curvature of arrows
there are extra circles detected.

3. Bad test cases:

test/badtest1

![screenshot 6][badtest1]

test/badtest2

![screenshot 7][badtest2]

Here even the states are not detected properly.

I think this can be fixed when arrow detection is done.

The circles which share a common arc with the arrows must be deleted.

[test1]: https://github.com/anirudh-c/furry-spork-latex/blob/dfa-shape-detection/testout/test1.png "Test 1"

[test2]: https://github.com/anirudh-c/furry-spork-latex/blob/dfa-shape-detection/testout/test2.png "Test 2"

[test3]: https://github.com/anirudh-c/furry-spork-latex/blob/dfa-shape-detection/testout/test3.png "Test 3"

[test4]: https://github.com/anirudh-c/furry-spork-latex/blob/dfa-shape-detection/testout/test4.png "Test 4"

[test5]: https://github.com/anirudh-c/furry-spork-latex/blob/dfa-shape-detection/testout/test5.png "Test 5"

[badtest1]: https://github.com/anirudh-c/furry-spork-latex/blob/dfa-shape-detection/testout/badtest1.png "Bad Test 1"

[badtest2]: https://github.com/anirudh-c/furry-spork-latex/blob/dfa-shape-detection/testout/badtest2.png "Bad Test 2"
Binary file added test/badtest1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/badtest2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/test1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/test2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/test3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/test4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/test5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testout/badtest1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testout/badtest2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testout/test1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testout/test2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testout/test3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testout/test4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testout/test5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f485481

Please sign in to comment.