How to run 'numpy' to change that the image to binary bits

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
destoriNAVY
Posts: 13
Joined: Wed Jan 20, 2021 7:19 am

How to run 'numpy' to change that the image to binary bits

Post by destoriNAVY » Wed Jan 20, 2021 7:30 am

I tried the MicroPython board first time

I don't know How to run 'numpy' to change that the image to binary bits in MicroPython

I saw that someone said we cannot use numpy in micro python board

then, is there any other way to convert image to binary?

and Second, Can I 'run' in PyCharm?

because When coding, I have to code while watching the result, but I have to press ctrl+D in putty, but it is very inconvenient to execute.

Below is that I want to execute, But the 'with open('C:\\Users\PKNU\Desktop\photo4.jpg', 'rb') as b:
data = b.read()' this part is also cannot run in putty

Thanks to read my questions :)

If you can afford it, thank you for your answer

Code: Select all

import numpy as np
with open('C:\\Users\PKNU\Desktop\photo4.jpg', 'rb') as b:
    data = b.read()
encoded = np.frombuffer(data, dtype=np.uint8)
length=len(encoded)
for i in range(length):
    a=format((encoded[i]),'b')
    print('%08d'%int(a))
    

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: How to run 'numpy' to change that the image to binary bits

Post by rcolistete » Wed Jan 20, 2021 9:05 pm

Use a Pyboard firmware with ulab included and read the docs of ulab.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

destoriNAVY
Posts: 13
Joined: Wed Jan 20, 2021 7:19 am

Re: How to run 'numpy' to change that the image to binary bits

Post by destoriNAVY » Thu Jan 21, 2021 4:40 am

then, How can I extract an image from the desktop?

like, in python,
with open('C:\\Users\PKNU\Desktop\photo4.jpg', 'rb') as b:
data = b.read()

like this

destoriNAVY
Posts: 13
Joined: Wed Jan 20, 2021 7:19 am

Re: How to run 'numpy' to change that the image to binary bits

Post by destoriNAVY » Thu Jan 21, 2021 7:58 am

I'm really sorry that keep asking

(1)
But, I cannot find the code that change image to binary and extract image from desktop

(2)
Also, many examples are 'PY file' or 'C file',

So, I don't know how to 'run' those files

destoriNAVY
Posts: 13
Joined: Wed Jan 20, 2021 7:19 am

Re: How to run 'numpy' to change that the image to binary bits

Post by destoriNAVY » Thu Jan 21, 2021 8:23 am

the last question that there is 'STM Device in DFU Mode' in Universal Serial Bus controllers

but there is not Pyboard USB Comm Port(COM00) in Ports although I connected pyboard

what do I need to do?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: How to run 'numpy' to change that the image to binary bits

Post by jimmo » Thu Jan 21, 2021 12:40 pm

destoriNAVY wrote:
Thu Jan 21, 2021 8:23 am
the last question that there is 'STM Device in DFU Mode' in Universal Serial Bus controllers
Which pyboard do you have?

DFU is the firmware update mode. This would normally only happen because the BOOT0 pin is activated.

If it's happening on its own, then you need to flash new firmware onto it. All official pyboards are shipped with firmware so this shouldn't happen normally.
destoriNAVY wrote:
Thu Jan 21, 2021 4:40 am
then, How can I extract an image from the desktop?
You would first need to copy the file to to the pyboard's internal flash. This can be done by copying the file to the virtual flash drive that shows up when the pyboard is connected to your PC.

You could then use something like https://github.com/remixer-dec/mpy-img-decoder to decode the jpeg.

destoriNAVY
Posts: 13
Joined: Wed Jan 20, 2021 7:19 am

Re: How to run 'numpy' to change that the image to binary bits

Post by destoriNAVY » Thu Jan 21, 2021 12:51 pm

I have the micro python board v1.1

Is the BOOT0 pin that you said P1(DFU)?

the final goal that is to change image to binary type, like 101010101100...

and I wanna make the square waveform using that binary

So, someone said to me using DFU mode for using 'ulab'

Is this way correct?

destoriNAVY
Posts: 13
Joined: Wed Jan 20, 2021 7:19 am

Re: How to run 'numpy' to change that the image to binary bits

Post by destoriNAVY » Thu Jan 21, 2021 12:54 pm

This can be done by copying the file to the virtual flash drive that shows up when the pyboard is connected to your PC.
But when I connected my pyboard to my PC, there is no virtual flash drive. :(

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: How to run 'numpy' to change that the image to binary bits

Post by jimmo » Thu Jan 21, 2021 1:00 pm

destoriNAVY wrote:
Thu Jan 21, 2021 12:51 pm
Is the BOOT0 pin that you said P1(DFU)?
See https://github.com/micropython/micropyt ... are-Update

So it sounds like you're trying to flash the ulab firmware (which is how you've ended up in DFU mode).

ulab is a micro version of numpy, but as far as I'm aware, it doesn't include any image compression features. So I'm not quite sure that's going to help you here. Might be worth taking a look at that other link I gave you.

So now the board is in DFU mode, you can use the instructions above to flash back the original firmware -- http://micropython.org/resources/firmwa ... -v1.13.dfu (or hopefully just remove the jumper to go back to the existing firwmare).
destoriNAVY wrote:
Thu Jan 21, 2021 12:54 pm
But when I connected my pyboard to my PC, there is no virtual flash drive.
Yep, that's because it's in DFU mode. Once you get back to normal mode (either remove the jumper, or flash the official firmware back on) you'll see the flash drive.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: How to run 'numpy' to change that the image to binary bits

Post by jimmo » Thu Jan 21, 2021 1:02 pm

FWIW, there is no "P1" on the Pyboard 1.1... can you link to exactly which board you have?

Post Reply