可以借助OpenCV库和Python中的imread函数和cvtColor函数来实现该问题的解决。具体步骤如下:
import cv2
img = cv2.imread('arabic_image.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
num_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(binary, connectivity=8)
char_components = []
for i in range(1, num_labels): # avoid background
if stats[i, cv2.CC_STAT_AREA] >= 200 and stats[i, cv2.CC_STAT_WIDTH] <= 80 and stats[i, cv2.CC_STAT_HEIGHT] <= 80: # filter small regions
component = binary.copy()
component[labels != i] = 0
char_components.append(component)
for i, char_component in enumerate(char_components):
cv2.imwrite(f'char_{i}.jpg', char_component)