[英]Open an image from an archive and load into cv2
我正在嘗試將存檔中的圖像加載到 CV2 中。
我的文件語句是存檔路徑。
file = "Final/small_img.zip"
接下來,我嘗試循環打開存檔一個圖像:
#import the zipfile as archive
with zipfile.ZipFile(file, 'r') as archive:
#get the filename of all files in the archive and append to a list
archive_file = archive.namelist()
#Test initial program with a single image
news = archive.open(archive_file[0])
pic = cv.imread(news)
#pic = Image.open(news)
我可以使用 Image.open(news) 使用 PIL 打開圖像,但由於我不會同時運行 pytesseract 和 haarcascade,因此我需要數組中的圖像。
我發現了我的問題,我忘記導入 numpy ....
#import the zipfile as archive
with zipfile.ZipFile(file, 'r') as archive:
#get the filename of all files in the archive and append to a list
archive_file = archive.namelist()
# Test initial program with a single image
news = archive.open(archive_file[0])
pic = Image.open(news)
pic_arr = np.array(pic)
#Test tesseract
#im1 = pytesseract.image_to_boxes(pic)
im1 = pytesseract.image_to_string(pic)
faces = face_cascade.detectMultiScale(pic_arr)
print(f"{len(faces)} faces detected in the image.")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.