Python Forum
Help me get this image converter code working?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help me get this image converter code working?
#1
Hello, I have been trying to convert 8-bit images into the proper binary format required by the Arduino IDE library I am using. The library included this python code for converting the images, and I have tried to get it to run with no success. I have had minor success with the software created by MIT called, "The Dot Factory" but the closest I have come to displaying my image correctly, is still unacceptable. The python image converter code below must be mixing up the data in some strange way to display it correctly on my SSD1306 OLED display. Here you can see my best attempt with The Dot Factory converting my image to binary:(the yellow/blue color is normal for this 2-color display)

[Image: Image-Display-Failure.jpg]

Here is the original image before binary conversion:

[Image: fbtest.png]

This SSD1306 display has 8 pages of memory, each page refers to a row of 8 pixels on the display. Somehow these rows or pages in memory are being swapped around, and exactly how it is swapping them should tell me what I need to do to my binary image data to make it compatible, but I am at a loss by now. I have tried changing the bit-order and layout in The Dot Factory, but I am thinking the setting I need is not available in this software. The above image was converted with these settings:

[Image: The-Dot-Factory-Settings.png]

If any kind soul has some recommendation for me to explore, I would be very grateful. If I cannot solve this, I will have to go back to the drawing board to find another suitable library for my Teensy 3.2 and these SSD1306 I2C displays. "EvilOLED" was the first library I found that actually worked; I didn't realize it'd be so difficult to find one. The reason it is difficult is that the breakout board for the display has no "RST" reset pin, which all the other SSD1306 libraries require. Anyhow, here is that code for the image converter written in python, that I could not get working:

#You must add numpy and Image packages to Python and verify your Python install
#Syntax: c:\Scripts\Python> converter.py <yourFileName>
import sys
import numpy
from PIL import Image

im = Image.open(sys.argv[1])
im = im.convert("1") 
rows = (im.size[1] // 8)
cols = im.size[0]
val = ""

print("const int bmap[8]= {")

for p in range(rows):
    for xx in range(cols):
        for yy in range(8):
            pix = im.getpixel((xx,(p * 8) + yy))
            if (pix == 0):
                val = "1" + val
            else:
                val = "0" + val
            val = "B" + val
            print(val + ",", end='')
            val = ""
            if (xx % 8 == 7):
                print("")

print("}")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code decode, string, image ... teckow 2 736 Aug-20-2021, 07:02 PM
Last Post: teckow
  Illegal instruction? working code for months? korenron 4 2,258 Aug-05-2021, 09:57 AM
Last Post: korenron
  I don't undestand why my code isn't working. RuyCab 2 721 Jun-17-2021, 03:06 PM
Last Post: RuyCab
  [split] Kera Getting errors when following code example Image classification from scratch hobbyist 3 2,563 Apr-13-2021, 01:26 PM
Last Post: amirian
  image.thumbnail(width, height) not working PCesarano 2 1,238 Apr-08-2021, 06:09 PM
Last Post: PCesarano
  code is not working , can anybody help? RandomPerson69 4 1,153 Mar-22-2021, 04:24 PM
Last Post: deanhystad
  Short code for EventGhost not working Patricia 8 1,376 Feb-09-2021, 07:49 PM
Last Post: Patricia
  Code no longer working yk303 14 3,581 Dec-21-2020, 10:58 PM
Last Post: bowlofred
  I need a code line to spam a keyboard key | Image detection bot Aizou 2 1,178 Dec-06-2020, 10:10 PM
Last Post: Aizou
  autocomplete working code sample not working... aviper4u 0 779 Oct-24-2020, 03:04 AM
Last Post: aviper4u

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020