basic firebrand recognition
Co-authored-by: Alex <AlexanderMcDowell@users.noreply.github.com>
This commit is contained in:
@@ -28,7 +28,11 @@ gray = cv.copyMakeBorder(
|
||||
value=0
|
||||
)
|
||||
|
||||
contours = measure.find_contours(array=gray, level=100)
|
||||
# cv.imshow('gray', gray)
|
||||
# cv.waitKey(0)
|
||||
|
||||
# contours = measure.find_contours(array=gray, level=100)
|
||||
_img, contours = cv.findContours(gray, cv.RETR_LIST, cv.CHAIN_APPROX_NONE)[0]
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.imshow(gray, cmap=plt.cm.gray, alpha=1)
|
||||
@@ -36,14 +40,37 @@ ax.imshow(gray, cmap=plt.cm.gray, alpha=1)
|
||||
def calculate_area(countour):
|
||||
c = np.expand_dims(countour.astype(np.float32), 1)
|
||||
c = cv.UMat(c)
|
||||
|
||||
|
||||
return cv.contourArea(c)
|
||||
|
||||
def center_of_mass(X):
|
||||
x = X[:,0]
|
||||
y = X[:,1]
|
||||
g = (x[:-1]*y[1:] - x[1:]*y[:-1])
|
||||
A = 0.5*g.sum()
|
||||
cx = ((x[:-1] + x[1:])*g).sum()
|
||||
cy = ((y[:-1] + y[1:])*g).sum()
|
||||
|
||||
return 1./(6*A)*np.array([cx,cy])
|
||||
|
||||
|
||||
img_new = cv.cvtColor(gray, cv.COLOR_GRAY2BGR)
|
||||
|
||||
for contour in contours:
|
||||
area = calculate_area(contour)
|
||||
|
||||
if calculate_area(contour) > 250:
|
||||
ax.plot(contour[:, 1], contour[:, 0], linewidth=0.5, color='orangered')
|
||||
|
||||
# if area > 250:
|
||||
# cnt = np.array(contour).reshape((-1, 1, 2)).astype(np.int32)
|
||||
# cv.drawContours(img_new, [cnt], -1, (0, 200, 255), thickness=10)
|
||||
|
||||
cv.drawContours(img_new, [contour], -1, (0, 200, 255), thickness=3)
|
||||
|
||||
# ax.plot(contour[:, 1], contour[:, 0], linewidth=0.5, color='orangered')
|
||||
|
||||
# cv.imshow('contours', img_new)
|
||||
# cv.waitKey(0)
|
||||
|
||||
cv.imwrite("firebrand_contours_opencv.png", img_new)
|
||||
|
||||
ax.axis('image')
|
||||
ax.set_xticks([])
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 83 KiB |
BIN
examples/pyrometry/firebrand_contours_opencv.png
Normal file
BIN
examples/pyrometry/firebrand_contours_opencv.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Reference in New Issue
Block a user