我有这个页面,我正试图使右上角的裁剪图像我用这个代码为左上角的黑色像素内,但无法编辑它的顶部工作right.it使一个网格。如果广场内有黑色像素是1号,否则是0。它找到左上方的黑色像素和作物周围。
input.jpg(您需要至少10个声望才能发布图像。)
output.jpg(您需要至少10个声望才能发布图像。
我正试图自动裁剪此页码区域what i wanna auto-crop(您需要至少10个信誉后的图像。)
我认为从像蓝色箭头脚本搜索,我想像红色how i think it search.jpg工作
import cv2
import numpy as np
# Load the cropped image in grayscale
image = cv2.imread('input.jpg', cv2.IMREAD_GRAYSCALE)
# Get the height and width of the image
h, w = image.shape
# Define the number of rows and columns of the grid
rows = 30
cols = 40
# Calculate the size of each square in pixels
square_h = h // rows
square_w = w // cols
# Create an empty array to store the grid values
grid = np.zeros((rows, cols), dtype=int)
# Loop over the rows and columns of the grid
for i in range(rows):
for j in range(cols):
# Get the coordinates of the top left corner of the square
x = j * square_w
y = i * square_h
# Get the sub-image corresponding to the square
square = image[y:y+square_h, x:x+square_w]
# Check if the square contains any black pixels
if np.any(square < 255):
# Set the grid value to 1
grid[i, j] = 1
# Find the top left corner with a 1 square
# Use np.argwhere to get the indices of the nonzero elements
# Use np.min to get the minimum row and column index
top_left = np.min(np.argwhere(grid == 1), axis=0)
# Get the row and column index of the top left corner
row, col = top_left
# Define the number of squares to crop around the corner
crop_size = 3
# Get the coordinates of the top left corner of the cropped region
x = col * square_w
y = row * square_h
# Get the sub-image corresponding to the cropped region
cropped_image = image[y:y+crop_size*square_h, x:x+crop_size*square_w]
# Save the result
cv2.imwrite('output.jpg', cropped_image)
字符串
无法为右上角工作
1条答案
按热度按时间w8f9ii691#
我将尝试找出如何裁剪模式
这是黑N白色页右上方是我想裁剪的图案,与多个偶数页的页码匹配,我上传的是一个示例图像
字符串
这是模式,我将尝试作物在这里是左上角(我试图找出如何,但我认为我会找到,或者我会问这里再次)
型
这是密码
型