Untitled
unknown
plain_text
a year ago
4.5 kB
3
Indexable
Never
######################################## croping image ############################# # -100 < dist < 100 controling the trashhold off croping for regular use send 1 def crop_image_with_margin(image, x, y, w, h, dist): # Calculate the margin distances based on the percentage x_margin = int(w * dist / 100) y_margin = int(h * dist / 100) # Calculate the new coordinates for the cropped rectangle x_cropped = max(0, x - x_margin) y_cropped = max(0, y - y_margin) w_cropped = min(image.shape[1], w + 2 * x_margin) h_cropped = min(image.shape[0], h + 2 * y_margin) # Perform the crop operation cropped_image = image[y_cropped:y_cropped + h_cropped, x_cropped:x_cropped + w_cropped] return cropped_image # resize the copy of the original image and returning the copy def resize_image(original_img): img_resize = imutils.resize(original_img, height=500) return img_resize # aporate gray ,blure , edeged , and returning edeged image u should keep copy ao the side def preprocess(copy): gray_image = cv2.cvtColor(copy, cv2.COLOR_BGR2GRAY) blurred_image = cv2.GaussianBlur(gray_image, (5, 5), 0) edged_img = cv2.Canny(blurred_image, 75, 200) return edged_img # scaling factors for update coordinates ####################################################################################################### def calculate_scaling_factors(original_image, resized_image): original_height,original_width, _ = original_image.shape resized_height,resized_width, _ = resized_image.shape scaling_factor_width = original_width / resized_width scaling_factor_height = original_height / resized_height return scaling_factor_width, scaling_factor_height def update_coordinates(resize_x, resize_y, resize_w, resize_h, scaling_factor_width, scaling_factor_height): original_x = resize_x * scaling_factor_width original_y = resize_y * scaling_factor_height original_w = resize_w * scaling_factor_width original_h = resize_h * scaling_factor_height return int(original_x), int(original_y), int(original_w), int(original_h) def find_image_to_stitch(teacher_coordinates, target): x0, x1 = teacher_coordinates[target] for i, tupel in enumerate(teacher_coordinates): if i == target: continue xi, xf = tupel if ((x1 < xi ) ) or ((x0 > xf )): print(x0,xi,x1,xf) return (target, i) return target , None def resize_images(images, target_size): resized_images = [] for image in images: # Resize the image resized_image = cv2.resize(image, target_size) resized_images.append(resized_image) return resized_images def load_images_from_folder(folder): images = [] for filename in os.listdir(folder): img_path = os.path.join(folder, filename) if os.path.isfile(img_path): img = cv2.imread(img_path) if img is not None: images.append(img) images = resize_images(images, (640, 480)) return images import cv2 import numpy as np import datetime global counter counter = 0 r=0 # ###########---Show Frames To Screen---############### # def x_frames(frames , x): # Show all 6 frames for i in range(x): cv2.imshow("Frame {} ".format(i+1), frames[i]) # Wait for the user to press a key cv2.waitKey(0) cv2.destroyAllWindows() def one_image(image ): global counter counter +=1 window_name = "Image call: " + str(counter) cv2.namedWindow(window_name, cv2.WINDOW_NORMAL) cv2.imshow(window_name , image) # Wait for the user to press a key cv2.waitKey(0) # Destroy all windows #cv2.destroyAllWindows() def one_pic(image): # Read the image from the path #image = cv2.imread(path) #image = enhance_image3(image) # Check if the image was successfully read if image is None: print("Error reading image file") return # Show the image on the screen cv2.namedWindow('Image', cv2.WINDOW_NORMAL) cv2.imshow("Image", image) # Wait for the user to press a key cv2.waitKey(0) # Destroy all windows cv2.destroyAllWindows() def closeWin(): # Destroy all windows cv2.destroyAllWindows()