(Python , OpenCV) Extract picture from picture

I want to extract each sticker 5x6 and to total 30 sticker
like below , how do I do so

(expect pic ) I wish to cut image like small pieces - Album on Imgur
(original picture) (Python , OpenCV) Extract picture from picture - Album on Imgur

  • following the suggestion:

The black pixels along the top are a distraction, so are the black
pixels of the QR codes. You are only interested in the white stickers.

So, take a copy of your image and threshold at a high value to give
you pure white stickers surrounded by black and with black QR codes
within each sticker. Now find white contours and reject black ones.

Apply the contours found on the thresholded image to your original

I’m doing the Thresholding expecting pure white stickers surrounded by black and with black QR codes within each sticker

import numpy as np
import glob
import matplotlib.pyplot as plt
import skimage.io
import skimage.color
import skimage.filters

from PIL import Image
import pytesseract
import cv2 as cv
import numpy as np

def custom_blur_demo(image):
    kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]], np.float32) #锐化
    dst = cv.filter2D(image, -1, kernel=kernel)
    cv.imwrite("/home/joy/桌面/test_11_4/sharpen_images.png", dst)
    cv.imshow("custom_blur_demo", dst)
src = cv.imread("/home/joy/桌面/test_11_4/original.png")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)


# load the image
image = skimage.io.imread("/home/joy/桌面/test_11_4/sharpen_images.png")[:,:,:3]

# image = imageio.imread(image_name)[:,:,:3]
# img = rgb2gray(image)

fig, ax = plt.subplots()

# convert the image to grayscale
gray_image = skimage.color.rgb2gray(image)

# blur the image to denoise
blurred_image = skimage.filters.gaussian(gray_image, sigma=1.0)

fig, ax = plt.subplots()
plt.imshow(blurred_image, cmap="gray")

# create a histogram of the blurred grayscale image
histogram, bin_edges = np.histogram(blurred_image, bins=256, range=(0.0, 1.0))

fig, ax = plt.subplots()
plt.plot(bin_edges[0:-1], histogram)
plt.title("Grayscale Histogram")
plt.xlabel("grayscale value")
plt.xlim(0, 1.0)

# create a mask based on the threshold
t1 = 0.72
t2 = 0.05
binary_mask = blurred_image < t1 

fig, ax = plt.subplots()
plt.imshow(binary_mask, cmap="gray")

aaa = plt.imshow(binary_mask, cmap="gray")


plt.savefig("/home/joy/桌面/test_11_4/sharpen_images_del_gray_part.png", aaa)

img = Image.open('/home/joy/桌面/test_11_4/sharpen_images_del_gray_part.png')
text = pytesseract.image_to_string(img, lang='eng')

print("file name" ,"final output", ".png")




the product does after Thresholding but the word on every sticker seems blur (I’m going to OCR image to text every single sticker img later)

  • (pic 5) in same imgur link on top , I set T value in 0.72
    (not correct yet, I want sticker part only (without gray color part) )


I asked on other discussion too, but thanks