forked from djdunc/casa0018
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
139 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Week5/arduino/TinyMLkit_CapturerawBytes/TinyMLkit_CapturerawBytes.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
OV767X - Camera Capture Raw Bytes | ||
This sketch reads a frame from the OmniVision OV7675 camera | ||
and writes the bytes to the Serial port. Use the Procesing | ||
sketch in the extras folder to visualize the camera output. | ||
This example code is in the public domain. | ||
*/ | ||
|
||
#include <Arduino_OV767X.h> | ||
|
||
int bytesPerFrame; | ||
|
||
byte data[176 * 144 * 2]; // QVGA: 320x240 X 2 bytes per pixel (RGB565) | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
//while (!Serial); | ||
|
||
if (!Camera.begin(QVGA, RGB565, 1, OV7675)) { | ||
Serial.println("Failed to initialize camera!"); | ||
while (1); | ||
} | ||
Serial.println("Initialize camera!"); | ||
|
||
bytesPerFrame = Camera.width() * Camera.height() * Camera.bytesPerPixel(); | ||
|
||
// Optionally, enable the test pattern for testing | ||
// Camera.testPattern(); | ||
} | ||
|
||
void loop() { | ||
Camera.readFrame(data); | ||
|
||
Serial.write(data, bytesPerFrame); | ||
} |
82 changes: 82 additions & 0 deletions
82
Week5/arduino/processing/TinyMLKit_VisualiseRawBytes/TinyMLKit_VisualiseRawBytes.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
This sketch reads a raw Stream of RGB565 pixels | ||
from the Serial port and displays the frame on | ||
the window. | ||
Use with the Examples -> CameraCaptureRawBytes Arduino sketch. | ||
This example code is in the public domain. | ||
*/ | ||
|
||
import processing.serial.*; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
|
||
Serial myPort; | ||
|
||
// must match resolution used in the sketch | ||
final int cameraWidth = 176; | ||
final int cameraHeight = 144; | ||
|
||
final int cameraBytesPerPixel = 2; | ||
|
||
final int bytesPerFrame = cameraWidth * cameraHeight * cameraBytesPerPixel; | ||
|
||
PImage myImage; | ||
|
||
void setup() | ||
{ | ||
size(176, 144); | ||
|
||
// if you have only ONE serial port active | ||
//myPort = new Serial(this, Serial.list()[0], 9600); // if you have only ONE serial port active | ||
|
||
// if you know the serial port name | ||
//myPort = new Serial(this, "COM3", 9600); // Windows | ||
//myPort = new Serial(this, "/dev/ttyACM0", 9600); // Linux | ||
myPort = new Serial(this, "/dev/cu.usbmodem14701", 9600); // Mac | ||
|
||
// wait for full frame of bytes | ||
myPort.buffer(bytesPerFrame); | ||
|
||
myImage = createImage(cameraWidth, cameraHeight, RGB); | ||
} | ||
|
||
void draw() | ||
{ | ||
image(myImage, 0, 0); | ||
} | ||
|
||
void serialEvent(Serial myPort) { | ||
byte[] frameBuffer = new byte[bytesPerFrame]; | ||
|
||
// read the saw bytes in | ||
myPort.readBytes(frameBuffer); | ||
|
||
// create image to set byte values | ||
PImage img = createImage(cameraWidth, cameraHeight, RGB); | ||
|
||
// access raw bytes via byte buffer | ||
ByteBuffer bb = ByteBuffer.wrap(frameBuffer); | ||
bb.order(ByteOrder.BIG_ENDIAN); | ||
|
||
int i = 0; | ||
|
||
img.loadPixels(); | ||
while (bb.hasRemaining()) { | ||
// read 16-bit pixel | ||
short p = bb.getShort(); | ||
|
||
// convert RGB565 to RGB 24-bit | ||
int r = ((p >> 11) & 0x1f) << 3; | ||
int g = ((p >> 5) & 0x3f) << 2; | ||
int b = ((p >> 0) & 0x1f) << 3; | ||
|
||
// set pixel color | ||
img.pixels[i++] = color(r, g, b); | ||
} | ||
img.updatePixels(); | ||
|
||
// assign image for next draw | ||
myImage = img; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters