Skip to content

Commit

Permalink
add option for min needle size
Browse files Browse the repository at this point in the history
  • Loading branch information
MattJeanes committed Feb 8, 2025
1 parent 3c3c888 commit 592a863
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions HomeAutomation.Web/BoilerGaugeReader/analog_gauge_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def calibrate_gauge(img, gauge_pixels_radius):

return x, y, r

def get_current_value(img, min_angle, max_angle, min_value, max_value, gauge_pixels_radius, debug):
def get_current_value(img, min_angle, max_angle, min_value, max_value, gauge_pixels_radius, min_needle_size, debug):
x, y, r = find_gauge(img, gauge_pixels_radius)

gray2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Expand All @@ -118,13 +118,13 @@ def get_current_value(img, min_angle, max_angle, min_value, max_value, gauge_pix

contours = cv2.findContours(dst2, mode=cv2.RETR_LIST, method=cv2.CHAIN_APPROX_SIMPLE)[-2]

# get contours that are closest to the circle of the gauge
# get contours that are closest to the circle of the gauge and above a minimum size
closest_contour = None
min_dist = 10000
for contour in contours:
(x1, y1), (w, h), angle = cv2.minAreaRect(contour)
dist = dist_2_pts(x, y, x1, y1)
if dist < min_dist:
if dist < min_dist and cv2.contourArea(contour) > min_needle_size:
closest_contour = contour
min_dist = dist

Expand All @@ -140,9 +140,10 @@ def get_current_value(img, min_angle, max_angle, min_value, max_value, gauge_pix
x1, y1 = all_points[np.argmax(dist_2_pts(x, y, all_points[:, 0], all_points[:, 1]))]

if debug:
cv2.drawContours(img, [closest_contour], -1, (255,0,0), 1)
cv2.drawContours(img, contours, -1, (255,0,0), 1)
# cv2.drawContours(img, [closest_contour], -1, (255,0,0), 1)
# show circle and center
# cv2.circle(img, (x, y), r, (255, 0, 0), 2)
cv2.circle(img, (x, y), r, (255, 0, 0), 2)
# show X (marks the spot) at the farthest point found
cv2.circle(img, (x1, y1), 5, (0, 0, 255), 2)
cv2.imshow('Show line', img)
Expand Down Expand Up @@ -201,6 +202,7 @@ def main():
required.add_argument("--max_angle", help="Max angle (highest possible angle) - in degrees", type=int, required=True)
required.add_argument("--min_value", help="Min value", type=float, required=True)
required.add_argument("--max_value", help="Max value", type=float, required=True)
required.add_argument("--min_needle_size", help="Min needle area size", type=float, required=True)

args = parser.parse_args()

Expand All @@ -210,7 +212,7 @@ def main():
calibrate_gauge(img, args.gauge_radius)
return

ang, val = get_current_value(img, args.min_angle, args.max_angle, args.min_value, args.max_value, args.gauge_radius, args.debug)
ang, val = get_current_value(img, args.min_angle, args.max_angle, args.min_value, args.max_value, args.gauge_radius, args.min_needle_size, args.debug)
# output json containing and and val
print('{"angle": %s, "value": %s}' % (ang, val))

Expand Down
2 changes: 2 additions & 0 deletions HomeAutomation.Web/Controllers/BoilerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public BoilerController(IOptions<BoilerOptions> options)
public async Task<BoilerResponse> GetBoilerPressure()
{
var framePath = await GetFrame();
// System.IO.File.Copy(framePath, @"E:\Matt\Downloads\testing\frame.jpg", true);
try
{
var processStartInfo = new ProcessStartInfo
Expand All @@ -36,6 +37,7 @@ public async Task<BoilerResponse> GetBoilerPressure()
processStartInfo.ArgumentList.Add($"--max_angle={_options.MaxAngle}");
processStartInfo.ArgumentList.Add($"--min_value={_options.MinValue}");
processStartInfo.ArgumentList.Add($"--max_value={_options.MaxValue}");
processStartInfo.ArgumentList.Add($"--min_needle_size={_options.MinNeedleSize}");
processStartInfo.ArgumentList.Add(framePath);
var process = new Process();
process.StartInfo = processStartInfo;
Expand Down
1 change: 1 addition & 0 deletions HomeAutomation.Web/Data/BoilerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public class BoilerOptions
public int MaxAngle { get; set; }
public int MinValue { get; set; }
public int MaxValue { get; set; }
public int MinNeedleSize { get; set; }
}

0 comments on commit 592a863

Please sign in to comment.