43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import cv2
|
|
|
|
import show_img_conditions
|
|
import remove_bg
|
|
import get_head
|
|
import coordinates_change
|
|
|
|
import numpy as np
|
|
#show_img_conditions.show()
|
|
|
|
image_path = get_head.get_image()
|
|
image = cv2.imread(image_path)
|
|
#cv2.imshow('Image', image)
|
|
|
|
image_path = 'image.png'
|
|
|
|
background_path = remove_bg.rmbg(image_path)
|
|
background = cv2.imread(background_path)
|
|
#cv2.imshow('Image without background', background)
|
|
|
|
gray_image = cv2.cvtColor(background, cv2.COLOR_BGR2GRAY)
|
|
edges = cv2.Canny(gray_image, 20, 80)
|
|
cv2.imshow("contours", edges)
|
|
cv2.waitKey(0)
|
|
|
|
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
|
|
|
x_offset = 0 # offset in the x_axis
|
|
y_offset = 0 # offset in the y_axis
|
|
new_size = [150, 0] # new size of the picture in mm, write 0 if you want to be proportional
|
|
|
|
[x_min, y_min, x_scale, y_scale] = coordinates_change.scale_calculator(contours, new_size)
|
|
|
|
x_offset = x_offset - x_min
|
|
y_offset = y_offset - y_min
|
|
|
|
new_coords = coordinates_change.coord(contours, x_offset, y_offset, x_scale, y_scale)
|
|
|
|
size = coordinates_change.get_size(new_coords)
|
|
print("x offset : ", int(x_offset+x_min), "mm")
|
|
print("y offset : ", int(y_offset+y_min), "mm")
|
|
print("size : ", int(size[0][1] - size[0][0]), "x", int(size[1][1] - size[1][0]), "mm")
|