Page 1 of 1

Convert images to .raw programs

Posted: Wed Jun 12, 2019 5:26 pm
by nibheis
Hi all,

To follow up on this thread, here is a python3 script that turns any 400x240 image into a .raw program for the DM42 (and free42).

It is basically one single class (Img2Hex) - you only need PIL or pillow Python package to use it.
Here's how to use it:

Code: Select all

from img2hex import Img2Hex

hexcode = Img2Hex(filename = 'matterhorn.bmp', label = 'MATT', negative = False)
hexcode.toRawFile('MATT.raw')
Assuming that 'matterhorn.bmp' is in the same directory, you will get a 'MATT.raw' program for your DM42, with LBL MATT.

You can also add payload into the program, like this:

Code: Select all

    # Prepare payload
    pl = {
        "V1": 1234,
        "V2": -3.1415,
        "VA": "Hello"
    }
    hx = Img2Hex(filename = 'matterhorn.bmp', label = 'MATT', negative = False, verbose = False, payload = pl)
When you execute the program on the DM42, the "V1", "V2" and "VA" variables are set to the corresponding values.
(I use payloads while creating charts for the DM42: the payload contains the scale, center coordinates and name of the displayed chart - more on this chart plotting app in another thread soon.)

Enjoy !

Re: Convert images to .raw programs

Posted: Sat Jan 04, 2020 12:18 am
by cappy
nibheis wrote:
Wed Jun 12, 2019 5:26 pm
Hi all,

To follow up on this thread, here is a python3 script that turns any 400x240 image into a .raw program for the DM42 (and free42).
Hi

I'm curious why you declared class variables at all, not to mention why
you declared some with the same as the variable names being passed in the Img2Hex.__init__() call?


class Img2Hex:
label = None
image = None
pix = None
w = None
h = None
b = None
oc = None
verbose = False
negative = False
payload = None


def __init__(self,
filename = None,
label = None,
verbose = False,
negative = False,
width = 400,
height = 240,
payload = None):


Class variables are only needed when you're sharing those variables among all
instances of the same class.

From what I see, there is only 1 instance of this class.

Not a problem, just curious