0

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.

Joey Fran
  • 598
  • 2
  • 24
  • 1
    Why are you calling `image_bytes = im.tobytes("xbm", "rgb")` if you want raw data? If you use `xbm` you'll get less data than you need and the decoder will not find enough data to decode... – Mark Setchell Jun 29 '23 at 16:05
  • Hello @MarkSetchell I changed it. I'm usint `tobytes()` to simulate my real problem. – Joey Fran Jun 29 '23 at 17:12
  • 1
    Try `print(len(image_bytes))` to see if it equals `width x height x 3` – Mark Setchell Jun 29 '23 at 17:17
  • @MarkSetchell same value: Total image size: 3264000, Total calculate: 3264000 – Joey Fran Jun 29 '23 at 17:24
  • @MarkSetchell I changed the code. the `im` object looks like the same type of `image_bytes` (first code block). – Joey Fran Jun 29 '23 at 17:38
  • 2
    What makes you think the fingerprint scanner delivers RGB? The documentation clearly says it delivers 320x480 8-bit grayscale. No wonder there aren't enough bytes to make it RGB. Use "L" instead. – Tim Roberts Jun 29 '23 at 17:39
  • 1
    What are the field values for the *size* structure? – CristiFati Jun 29 '23 at 18:18
  • @TimRoberts it makes sense. In this case... Should I use `size_width, size_height = im.size` or put the real values `320, 480`? – Joey Fran Jun 30 '23 at 13:11
  • @CristiFati 320, 480, and size = 153600. – Joey Fran Jun 30 '23 at 13:14
  • 2
    Your goal is to get your first snippet running, right? The rest was just testing. If `FTRSCAN_IMAGE_SIZE` returns the correct values, then use that. Just replace the `"RGB"` in the `frombytes` call with `"L"`. – Tim Roberts Jun 30 '23 at 18:57

0 Answers0