import cv2
def draw_bounding_box(image, x, y, w, h):
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.imshow("Image with Bounding Box", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
image_path = "path/to/your/image.jpg"
x = 100
y = 100
w = 200
h = 150
image = cv2.imread(image_path)
draw_bounding_box(image, x, y, w, h)
import cv2
import numpy as np
img = cv2.imread(r'C:\Users\lifan\Desktop\0afffc38803b6d42899ec84ede9b5a2.png')
array = np.sum(img[:,:,0],axis = 0)
for i in range(len(array)):
if(array[i]>0):
idx_y = i
break
for i in range(img.shape[0]):
if(img[i,idx_y,0]>0):
idx_x = i
break
for j in range(len(array)-1,0,-1):
if (array[j] > 0):
idx_y1 = j
break
for k in range(img.shape[0]-1,0,-1):
if(img[k,idx_y1,0]>0):
idx_x1 = k
break
cv2.circle(img, (idx_y,idx_x), 2, (0,0,255),1)
cv2.circle(img, (idx_y1,idx_x1), 2, (0,0,255),1)
cv2.imshow('a',img)
cv2.waitKey(0)
import os
def rename_images(folder_path):
image_extensions = ['.jpg', '.jpeg', '.png', '.gif']
image_files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))
and os.path.splitext(f)[1].lower() in image_extensions]
image_files.sort()
for i, file_name in enumerate(image_files):
new_name = str(i + 1).zfill(8) + os.path.splitext(file_name)[1]
old_path = os.path.join(folder_path, file_name)
new_path = os.path.join(folder_path, new_name)
os.rename(old_path, new_path)
folder_path = '/path/to/folder'
rename_images(folder_path)
import os
num_folders = 5
for i in range(1, num_folders+1):
folder_name = f"needle_{i}"
folder_path = os.path.join(os.getcwd(), folder_name)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
print(f"文件夹 '{folder_name}' 已创建成功!")
else:
print(f"文件夹 '{folder_name}' 已存在。")
subfolder_name = "image"
subfolder_path = os.path.join(folder_path, subfolder_name)
if not os.path.exists(subfolder_path):
os.makedirs(subfolder_path)
print(f"子文件夹 'image' 已在 '{folder_name}' 文件夹下创建成功!")
else:
print(f"子文件夹 'image' 已在 '{folder_name}' 文件夹下存在。")
file_content = "needle,line:This is the content, other stuff"
line_start_index = file_content.find("line:")
if line_start_index != -1:
comma_index = file_content.find(",", line_start_index)
if comma_index != -1:
extracted_content = file_content[line_start_index + len("line:"):comma_index]
print("提取的内容:", extracted_content)
else:
print("找不到逗号")
else:
print("找不到 line:")