Page 1 of 2

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

Posted: Wed Jan 20, 2021 7:30 am
by destoriNAVY
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))
    

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

Posted: Wed Jan 20, 2021 9:05 pm
by rcolistete
Use a Pyboard firmware with ulab included and read the docs of ulab.

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

Posted: Thu Jan 21, 2021 4:40 am
by destoriNAVY
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

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

Posted: Thu Jan 21, 2021 7:58 am
by destoriNAVY
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

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

Posted: Thu Jan 21, 2021 8:23 am
by destoriNAVY
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?

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

Posted: Thu Jan 21, 2021 12:40 pm
by jimmo
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.

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

Posted: Thu Jan 21, 2021 12:51 pm
by destoriNAVY
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?

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

Posted: Thu Jan 21, 2021 12:54 pm
by destoriNAVY
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. :(

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

Posted: Thu Jan 21, 2021 1:00 pm
by jimmo
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.

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

Posted: Thu Jan 21, 2021 1:02 pm
by jimmo
FWIW, there is no "P1" on the Pyboard 1.1... can you link to exactly which board you have?