Spaces:
Sleeping
Sleeping
Shri Jayaram
commited on
Commit
·
562fde0
1
Parent(s):
1c942f0
minor changes from local
Browse files
app.py
CHANGED
|
@@ -42,7 +42,7 @@ def calculate_pixel_per_metric(image, known_length_of_line=50): # Line length i
|
|
| 42 |
|
| 43 |
edges = cv2.Canny(grayed, 0, 150, apertureSize=3)
|
| 44 |
|
| 45 |
-
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, threshold=
|
| 46 |
if lines is not None:
|
| 47 |
longest_line = None
|
| 48 |
max_length = 0
|
|
@@ -60,7 +60,7 @@ def calculate_pixel_per_metric(image, known_length_of_line=50): # Line length i
|
|
| 60 |
pixel_per_metric = max_length / known_length_of_line
|
| 61 |
|
| 62 |
# Optionally draw the detected line on the image (you can remove this if not needed)
|
| 63 |
-
cv2.line(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 64 |
cv2.circle(image, (x1, y1), 5, (0, 0, 255), -1)
|
| 65 |
cv2.circle(image, (x2, y2), 5, (255, 0, 0), -1)
|
| 66 |
|
|
@@ -70,13 +70,15 @@ def process_image(image):
|
|
| 70 |
return remove(image)
|
| 71 |
|
| 72 |
def calculate_pip_width(image, original_img, pixel_per_metric):
|
|
|
|
|
|
|
| 73 |
def calSize(xA, yA, xB, yB, color_circle, color_line, img):
|
| 74 |
d = dist.euclidean((xA, yA), (xB, yB))
|
| 75 |
cv2.circle(img, (int(xA), int(yA)), 5, color_circle, -1)
|
| 76 |
cv2.circle(img, (int(xB), int(yB)), 5, color_circle, -1)
|
| 77 |
cv2.line(img, (int(xA), int(yA)), (int(xB), int(yB)), color_line, 2)
|
| 78 |
d_mm = d / pixel_per_metric
|
| 79 |
-
d_mm = d_mm - 1
|
| 80 |
cv2.putText(img, "{:.1f}".format(d_mm), (int(xA - 15), int(yA - 10)), cv2.FONT_HERSHEY_SIMPLEX, 0.65, (255, 255, 255), 2)
|
| 81 |
print(d_mm)
|
| 82 |
return d_mm
|
|
@@ -118,7 +120,7 @@ def calculate_pip_width(image, original_img, pixel_per_metric):
|
|
| 118 |
if len(contours) > 0:
|
| 119 |
cnt = max(contours, key=cv2.contourArea)
|
| 120 |
frame2 = cv2.cvtColor(og_img, cv2.COLOR_BGR2RGB)
|
| 121 |
-
handsLM = mp.solutions.hands.Hands(max_num_hands=1, min_detection_confidence=0.
|
| 122 |
pr = handsLM.process(frame2)
|
| 123 |
print(pr.multi_hand_landmarks)
|
| 124 |
if pr.multi_hand_landmarks:
|
|
@@ -153,7 +155,7 @@ def calculate_pip_width(image, original_img, pixel_per_metric):
|
|
| 153 |
d_mm_pip = calSize(x1_pip, y1_pip, x2_pip, y2_pip, (255, 0, 0), (255, 0, 255), original_img)
|
| 154 |
d_mm_mid = calSize(x1_mid, y1_mid, x2_mid, y2_mid, (0, 255, 0), (0, 0, 255), original_img)
|
| 155 |
|
| 156 |
-
largest_d_mm = max(
|
| 157 |
return original_img, largest_d_mm, imgcpy, marked_img
|
| 158 |
|
| 159 |
def mark_hand_landmarks(image_path):
|
|
@@ -220,8 +222,8 @@ st.write(
|
|
| 220 |
)
|
| 221 |
st.sidebar.write("## Upload :gear:")
|
| 222 |
#~~
|
| 223 |
-
st.write("### Workflow Overview")
|
| 224 |
-
st.image("FlowChart.png", caption="Workflow Overview", use_column_width=True)
|
| 225 |
|
| 226 |
st.write("### Detailed Workflow")
|
| 227 |
st.write("1. **Hough Circle Transform:** The Hough Circle Transform is a technique used to detect circles in an image. It works by transforming the image into a parameter space, identifying circles based on their radius and center coordinates. This method is effective for locating circular objects, such as a coin, within the image.")
|
|
|
|
| 42 |
|
| 43 |
edges = cv2.Canny(grayed, 0, 150, apertureSize=3)
|
| 44 |
|
| 45 |
+
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, threshold=50, minLineLength=1, maxLineGap=100)
|
| 46 |
if lines is not None:
|
| 47 |
longest_line = None
|
| 48 |
max_length = 0
|
|
|
|
| 60 |
pixel_per_metric = max_length / known_length_of_line
|
| 61 |
|
| 62 |
# Optionally draw the detected line on the image (you can remove this if not needed)
|
| 63 |
+
# cv2.line(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 64 |
cv2.circle(image, (x1, y1), 5, (0, 0, 255), -1)
|
| 65 |
cv2.circle(image, (x2, y2), 5, (255, 0, 0), -1)
|
| 66 |
|
|
|
|
| 70 |
return remove(image)
|
| 71 |
|
| 72 |
def calculate_pip_width(image, original_img, pixel_per_metric):
|
| 73 |
+
d_mm_mid = 0
|
| 74 |
+
d_mm_pip = 0
|
| 75 |
def calSize(xA, yA, xB, yB, color_circle, color_line, img):
|
| 76 |
d = dist.euclidean((xA, yA), (xB, yB))
|
| 77 |
cv2.circle(img, (int(xA), int(yA)), 5, color_circle, -1)
|
| 78 |
cv2.circle(img, (int(xB), int(yB)), 5, color_circle, -1)
|
| 79 |
cv2.line(img, (int(xA), int(yA)), (int(xB), int(yB)), color_line, 2)
|
| 80 |
d_mm = d / pixel_per_metric
|
| 81 |
+
d_mm = d_mm - 1
|
| 82 |
cv2.putText(img, "{:.1f}".format(d_mm), (int(xA - 15), int(yA - 10)), cv2.FONT_HERSHEY_SIMPLEX, 0.65, (255, 255, 255), 2)
|
| 83 |
print(d_mm)
|
| 84 |
return d_mm
|
|
|
|
| 120 |
if len(contours) > 0:
|
| 121 |
cnt = max(contours, key=cv2.contourArea)
|
| 122 |
frame2 = cv2.cvtColor(og_img, cv2.COLOR_BGR2RGB)
|
| 123 |
+
handsLM = mp.solutions.hands.Hands(max_num_hands=1, min_detection_confidence=0.8, min_tracking_confidence=0.8)
|
| 124 |
pr = handsLM.process(frame2)
|
| 125 |
print(pr.multi_hand_landmarks)
|
| 126 |
if pr.multi_hand_landmarks:
|
|
|
|
| 155 |
d_mm_pip = calSize(x1_pip, y1_pip, x2_pip, y2_pip, (255, 0, 0), (255, 0, 255), original_img)
|
| 156 |
d_mm_mid = calSize(x1_mid, y1_mid, x2_mid, y2_mid, (0, 255, 0), (0, 0, 255), original_img)
|
| 157 |
|
| 158 |
+
largest_d_mm = max(d_mm_mid,d_mm_pip)
|
| 159 |
return original_img, largest_d_mm, imgcpy, marked_img
|
| 160 |
|
| 161 |
def mark_hand_landmarks(image_path):
|
|
|
|
| 222 |
)
|
| 223 |
st.sidebar.write("## Upload :gear:")
|
| 224 |
#~~
|
| 225 |
+
# st.write("### Workflow Overview")
|
| 226 |
+
# st.image("FlowChart.png", caption="Workflow Overview", use_column_width=True)
|
| 227 |
|
| 228 |
st.write("### Detailed Workflow")
|
| 229 |
st.write("1. **Hough Circle Transform:** The Hough Circle Transform is a technique used to detect circles in an image. It works by transforming the image into a parameter space, identifying circles based on their radius and center coordinates. This method is effective for locating circular objects, such as a coin, within the image.")
|