I'm trying to make a Futronic FS88 fingerprint reader to work.
I'm using this reference: python ctypes issue on different OSes
The code its work. But now, I want to save the fingerprint in a file. But I'm getting the following error:
ValueError: not enough image data
The code I added, based on the above reference, is:
# ct = ctypes
size = FTRSCAN_IMAGE_SIZE()
result_size = lib.ftrScanGetImageSize(handle_device, ct.byref(size))
pbuffer = ct.create_string_buffer(size.nImageSize)
result_frame = lib.ftrScanGetFrame(handle_device, pbuffer, None)
image_bytes = ct.string_at(pbuffer, size.nImageSize)
image = Image.frombytes("RGB", (size.nWidth, size.nHeight), image_bytes)
I'm receiving the error on the line image = Image.frombytes("RGB", (size.nWidth, size.nHeight), image_bytes)
.
To better understand it, I created the following code:
from PIL import Image
im = Image.open("/home/joca/Images/802610961_20633.jpg")
image_bytes = im.tobytes("raw")
size_width, size_height = im.size
image = Image.frombytes(
"RGB", (size_width, size_height), image_bytes, decoder_name="raw"
)
It generates the same error error ValueError: not enough image data
.
My doubt is here. I am able to make it work when I use values below 500 (width and height). However, whenever I go above that, I always receive this error.
Changes
I change this block:
from PIL import Image
im = Image.open("/home/joca/Images/802610961_20633.jpg")
image_bytes = im.tobytes("raw")
size_width, size_height = im.size
image = Image.frombytes(
"RGB", (size_width, size_height), image_bytes, decoder_name="raw"
)
For this:
with open("/home/joca/Images/802610961_20633.jpg", "rb") as f:
im = f.read()
print(type(im))
print(dir(im))
image = Image.open(io.BytesIO(im))
looks ok to me. I will test it.