Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving snapshot to sd cardd #81

Open
anku2424 opened this issue Apr 22, 2020 · 0 comments
Open

Saving snapshot to sd cardd #81

anku2424 opened this issue Apr 22, 2020 · 0 comments

Comments

@anku2424
Copy link

Hi team,

I wanted to save snapshot taken by maix one dock board to the sd card. Here's the code I wrote for it.

`#include <Sipeed_OV2640.h>
#include <Sipeed_ST7789.h>

#include<SD.h>

SPIClass spi0(SPI0); // MUST be SPI0 for Maix series on board LCD
Sipeed_ST7789 lcd(320, 240, spi0);

Sipeed_OV2640 camera(FRAMESIZE_QVGA, PIXFORMAT_RGB565);

File myFile;
File myFile2;
File myFile3;
File myFile4;

#define SWAP_SMALL(x) (x >> 8 & 0xff)
#define SWAP_16(x) ((x >> 8 & 0xff) | (x << 8))
#define LCD_MAX_PIXELS (76800)

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(100);
Serial.print("Initializing SD card...");

if (!SD.begin(29)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");

myFile = SD.open("forl2.txt", FILE_WRITE);

lcd.begin(15000000, COLOR_RED);
lcd.invertDisplay(true); // comment this out when camera is on the backside

Serial.print("camera init ");
if(!camera.begin())
Serial.println("failed");
else
Serial.println("success");
camera.run(true);

delay(100);

uint8_t* img = camera.snapshot();

if (myFile) {
for (uint32_t i=0;i<320240;i+=2) {
myFile.write(
(img+i+1));
myFile.write(*(img+i));
}

Serial.println("file written successfully");

}
else {
Serial.println("FIle opening failed");
}

myFile.close();
}

void loop() {
// put your main code here, to run repeatedly:
}`

Then I wrote a python code using PIL library to display the image saved by maix 1 dock board.

`import numpy as np
from PIL import Image
from numpy import asarray

data = list()

with open("FORL2.txt", "rb") as f:
byte = f.read(1)
while byte != b"":
# print (byte)
data.append(int.from_bytes(byte, "big"))
# Do stuff with byte.
byte = f.read(1)

data = np.array(data)
image_array = np.reshape(data, (240, 320))

image2 = Image.fromarray(image_array)

image2.show()`

I took the image of my face but here's the image that was displayed by the python code -

my_image

Where am I going wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant