owned this note
owned this note
Published
Linked with GitHub
# canny test
https://stackoverflow.com/questions/41020357/orientational-canny-edge-detection
https://docs.opencv.org/3.4/d4/d86/group__imgproc__filter.html#gacea54f142e81b6758cb6f375ce782c8d


```
if abs(rec_distance) < 10 or x_mid_left <= x_left or x_list_temp <= 300 or x_list_temp >= 560:
second_stg_line_matrix = line_matrix[int(seq - 2)] + line_matrix[int(seq - 1)]
# print(f"no.{int(seq / 2 + 0.5)} too_close distance:{rec_distance}")
try:
left_angle, _, _, _, _, long_line_slope = get_maxlength_line_angle(
line_matrix[int(seq - 3)])
x1, y1, x2, y2 = angle_filter_and_maxlinegap(
left_angle, second_stg_line_matrix, log_dir=output_dir)
if not length_matrix[int(seq - 2)]:
length_matrix[int(seq - 2)] = round(
math.sqrt((y2 - y1) ** 2 + (x2 - x1) ** 2) * np.sin(
abs(left_angle * np.pi / 180.)))
if left_angle >= 0:
dx1 = x1
dx2 = x2
else:
dx1 = x2
dx2 = x1
cv2.line(fix_image, (dx2 + h_crop_x1 - crop_x1, y1 + h_crop_y1 - crop_y1),
(dx1 + h_crop_x1 - crop_x1, y2 + h_crop_y1 - crop_y1), (0, 0, 255), 2)
cv2.putText(fix_image, str(length_matrix[int(seq - 2)]),
(x2 + h_crop_x1 - crop_x1, y1 + h_crop_y1 - crop_y1),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
if length_matrix[int(seq - 3)] >= minLineLength and length_matrix[
int(seq - 2)] >= minLineLength:
line_matrix_result.append(
[line_matrix[int(seq - 3)][0][8], x_list.copy(), frame_time,
long_line_slope])
right_angle, _, _, _, _, long_line_slope = get_maxlength_line_angle(
line_matrix[int(seq)])
x1, y1, x2, y2 = angle_filter_and_maxlinegap(right_angle, second_stg_line_matrix,
log_dir=output_dir)
if not length_matrix[int(seq - 1)]:
length_matrix[int(seq - 1)] = round(
math.sqrt((y2 - y1) ** 2 + (x2 - x1) ** 2) * np.sin(
abs(right_angle * np.pi / 180.)))
if right_angle >= 0:
dy1 = y1
dy2 = y2
else:
dy1 = y2
dy2 = y1
cv2.line(fix_image, (x1 + h_crop_x1 - crop_x1, dy1 + h_crop_y1 - crop_y1),
(x2 + h_crop_x1 - crop_x1, dy2 + h_crop_y1 - crop_y1), (0, 0, 0), 2)
cv2.putText(fix_image, str(length_matrix[int(seq - 1)]),
(x2 + h_crop_x1 - crop_x1, dy1 + h_crop_y1 - crop_y1),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 1, cv2.LINE_AA)
cv2.imwrite(f"{output_dir}/detail/{initial_time}_{frame_time}_fix.jpg",
fix_image)
if length_matrix[int(seq)] >= minLineLength and length_matrix[
int(seq - 1)] >= minLineLength:
line_matrix_result.append(
[line_matrix[int(seq - 1)][0][8], x_list.copy(), frame_time,
long_line_slope])
with open(f"{output_dir}/logs//line_after_process_length.txt", 'a+') as f:
f.write(
f"after_two_stg seq: {int(seq - 1)} length:{length_matrix[int(seq - 1)]} seq: {int(seq - 2)} length:{length_matrix[int(seq - 2)]} \n")
except:
with open(f"{output_dir}/logs//line_after_process_length.txt", 'a+') as f:
f.write(
f"after_two_stg fail\n")
```