Measure max arc angle
This commit is contained in:
parent
492b7d32c7
commit
c1875aedee
51
3/hough.py
51
3/hough.py
|
@ -1,51 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2018 pavle <pavle.portic@tilda.center>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
|
||||
def main():
|
||||
filename = "set/A1.png"
|
||||
src = cv.imread(filename)
|
||||
# dst = cv.Canny(src, 50, 200, None, 3)
|
||||
|
||||
edges = cv.Canny(src, 20, 250, apertureSize = 3)
|
||||
lines = cv.HoughLinesP(edges, 1, np.pi/180, 100, minLineLength=100, maxLineGap=10)
|
||||
dest = cv.cvtColor(edges, cv.COLOR_GRAY2BGR)
|
||||
|
||||
for line in lines:
|
||||
x1,y1,x2,y2 = line[0]
|
||||
# cv.line(dest, (x1, y1), (x2, y2), (0, 0, 255), 2)
|
||||
|
||||
cv.imshow('Detected', dest)
|
||||
cv.waitKey()
|
||||
|
||||
# cdst = cv.cvtColor(dst, cv.COLOR_GRAY2BGR)
|
||||
# lines = cv.HoughLines(dst, 1, np.pi / 180, 150, None, 0, 0)
|
||||
|
||||
# if lines is not None:
|
||||
# for i in [ 0 ]:
|
||||
# rho = lines[i][0][0]
|
||||
# theta = lines[i][0][1]
|
||||
# a = np.cos(theta)
|
||||
# b = np.sin(theta)
|
||||
# x0 = a * rho
|
||||
# y0 = b * rho
|
||||
# pt1 = (int(x0 + 1000*(-b)), int(y0 + 1000*(a)))
|
||||
# pt2 = (int(x0 - 1000*(-b)), int(y0 - 1000*(a)))
|
||||
# cv.line(cdst, pt1, pt2, (0,0,255), 3, cv.LINE_AA)
|
||||
# print type(lines)
|
||||
|
||||
# cv.imshow("Source", src)
|
||||
# cv.imshow("Detected Lines (in red) - Standard Hough Line Transform", cdst)
|
||||
# cv.waitKey()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
28
3/proba.py
28
3/proba.py
|
@ -1,28 +0,0 @@
|
|||
import cv2 as cv
|
||||
import numpy as np
|
||||
|
||||
images = ['set/A1.png','set/A2.png','set/A3.png','set/A4.png','set/A5.png','set/A6.png','set/A7.png','set/A8.png','set/A9.png','set/A10.png']
|
||||
|
||||
|
||||
def main():
|
||||
i = images[4]
|
||||
img = cv.imread(i, 0)
|
||||
|
||||
kernel = np.ones((5,5),np.uint8)
|
||||
closing = cv.morphologyEx(img, cv.MORPH_CLOSE, kernel)
|
||||
|
||||
cv.imshow("Closing", closing)
|
||||
cv.imshow("Source", img)
|
||||
cv.waitKey()
|
||||
|
||||
|
||||
def rotateImage(image, angle):
|
||||
image_center = tuple(np.array(image.shape)/2)
|
||||
rot_mat = cv.getRotationMatrix2D(image_center,angle,1.0)
|
||||
result = cv.warpAffine(image, rot_mat, image.shape,flags=cv.INTER_LINEAR)
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -5,13 +5,11 @@
|
|||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
import sys
|
||||
import math
|
||||
import cv2 as cv
|
||||
import os
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
def main(argv):
|
||||
def main():
|
||||
root = raw_input()
|
||||
# root = 'set/example_4'
|
||||
filename = [f for f in os.listdir(root) if os.path.isfile(os.path.join(root, f))]
|
||||
|
@ -27,7 +25,10 @@ def main(argv):
|
|||
cv.line(src, (l[0], l[1]), (l[2], l[3]), (0,0,255), 1, cv.LINE_AA)
|
||||
|
||||
circle = detect_circle(img)
|
||||
print circle[0], circle[1], len(lines)/2, 0, 0, 0, 0
|
||||
|
||||
arc = measure_arc(img, circle[2], (circle[0], circle[1]))
|
||||
|
||||
print circle[0], circle[1], len(lines)/2, 0, arc, 0, 0
|
||||
|
||||
# cv.imshow("Probabilistic Line Transform", src)
|
||||
# cv.imshow("Canny", canny)
|
||||
|
@ -53,11 +54,75 @@ def detect_circle(img):
|
|||
|
||||
if circles is not None:
|
||||
circles = np.uint16(np.around(circles))
|
||||
return circles[0][0][0], circles[0][0][1]
|
||||
return circles[0][0]
|
||||
|
||||
return 0, 0
|
||||
return [0, 0, 0]
|
||||
|
||||
|
||||
def measure_arc(img, r, c):
|
||||
r += 2
|
||||
phi = 10
|
||||
|
||||
while True:
|
||||
x, y = np.int0(pol2car(r, phi))
|
||||
x += c[0]
|
||||
y += c[1]
|
||||
if img[y, x] > 128:
|
||||
break
|
||||
|
||||
phi += 2
|
||||
if phi == 360:
|
||||
return 360
|
||||
|
||||
arcs = []
|
||||
while True:
|
||||
curr_phi = 0
|
||||
max_phi = 0
|
||||
p = phi + 1
|
||||
while True:
|
||||
x, y = np.int0(pol2car(r, p))
|
||||
x += c[0]
|
||||
y += c[1]
|
||||
|
||||
if img[y, x] < 255:
|
||||
curr_phi += 1
|
||||
else:
|
||||
if curr_phi > max_phi:
|
||||
max_phi = curr_phi
|
||||
curr_phi = 0
|
||||
|
||||
if p == phi:
|
||||
break
|
||||
|
||||
# print curr_phi
|
||||
# copy = cv.cvtColor(img, cv.COLOR_GRAY2BGR)
|
||||
# cv.circle(copy, (x, y), 1, (0, 0, 255), 2)
|
||||
# cv.imshow("rotate", copy)
|
||||
# cv.waitKey()
|
||||
|
||||
p += 1
|
||||
if p >= 360:
|
||||
p = 0
|
||||
|
||||
|
||||
if max_phi == 0:
|
||||
break
|
||||
|
||||
arcs.append(max_phi)
|
||||
r += 5
|
||||
|
||||
return max(arcs)
|
||||
|
||||
|
||||
def car2pol(x, y):
|
||||
return np.sqrt(x**2 + y**2), np.arctan2(y, x)
|
||||
|
||||
|
||||
def pol2car(r, p):
|
||||
p = np.radians(p)
|
||||
return r * np.cos(p), r * np.sin(p)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
main()
|
||||
|
Reference in New Issue