提问人:sHaDoW 提问时间:11/2/2023 更新时间:11/2/2023 访问量:38
错误:(-215:断言失败)函数“cv::imwrite”中的 _img.empty()
ERROR: (-215:Assertion failed) !_img.empty() in function 'cv::imwrite'
问:
我正在尝试使用主密钥加密的概念,使用 AES-GCM 算法实现图像加密项目。通过访问网络摄像头并单击快照并在保存之前对其进行加密,加密代码可以正常工作。但是在解密图像时,代码显示错误,指出“错误:(-215:断言失败)!_img.empty()在函数'cv::imwrite'中”。如何解决此问题?
cipher = Cipher(algorithms.AES(derived_key), modes.GCM(iv, tag), backend=default_backend())
decryptor = cipher.decryptor()
# Decrypt the image
decrypted_data = decryptor.update(ciphertext) + decryptor.finalize()
# Convert the decrypted data to an image (assuming it was an image that was encrypted)
decrypted_image = cv2.imdecode(np.frombuffer(decrypted_data, np.uint8), cv2.IMREAD_COLOR)
# Define the path to the "Decrypted snaps" folder
decrypted_folder = "Decrypted snaps"
# Create the "Decrypted snaps" folder if it doesn't exist
if not os.path.exists(decrypted_folder):
os.makedirs(decrypted_folder)
# Extract the filename from the input path
filename = os.path.basename(encrypted_image_filename)
# Create the path to save the decrypted image in the "Decrypted snaps" folder
decrypted_image_path = os.path.join(decrypted_folder, filename)
print(decrypted_image_path)
# Save the decrypted image
cv2.imwrite(decrypted_image_path, decrypted_image)
print(f"Decrypted image saved as '{decrypted_image_path}'")
我之前使用 Fernet,我遇到了同样的问题,所以我切换到 GCM,但问题仍然存在。
答: 暂无答案
评论