如何打印qr_codes_found列表
时间: 2024-04-11 16:27:19 浏览: 103
要打印`qr_codes_found`列表,您可以在`main`函数的最后添加以下代码:
```python
print(qr_codes_found)
```
这将在运行完解码过程后打印出`qr_codes_found`列表的内容。
以下是更新后的代码示例:
```python
#!/usr/bin/env python3
import os
import sys
import cv2
from pyzbar import pyzbar
def main(image_folder_path, output_file_name):
img_files = [f for f in os.listdir(image_folder_path) if f.endswith(('.png'))]
qr_codes_found = []
for img_file in img_files:
img_path = os.path.join(image_folder_path,img_file)
img = cv2.imread(img_path)
barcodes = pyzbar.decode(img)
for barcode in barcodes:
if barcode.type == 'QRCODE':
qr_data = barcode.data.decode("utf-8")
qr_codes_found.append((img_file, qr_data))
with open(output_file_name,'w') as f:
for file_name,qr_content in qr_codes_found:
f.write(f"{file_name}: {qr_content}\n")
print(qr_codes_found)
if __name__ == "__main__":
image_folder_path = '/path/to/your/image/folder'
output_file_name = 'qr_codes_found.txt'
main(image_folder_path,output_file_name)
```
请将`/path/to/your/image/folder`替换为您的实际图像文件夹路径。运行代码后,您将看到在终端中打印出`qr_codes_found`列表的内容。
阅读全文