Hiya there, I am currently trying to make an application that has half the screen displaying a 'motion capture' image using frame differencing, and the other half to be just a regular camera. I have a separate application capturing the screen so I only need to preview the image, I am currently using Ketai Cam as shown down below. The Frame differencing is using some code from the Coding Train () which works well on my PC but transferring it to Android seems problematic.
Currently the image wraps itself along the screen and will only allow size formats equal to the camera resolutions, it also seems impossible to resize or transform apart from making the screen size itself smaller. I have linked an image of the current output. It's a mix up of various ideas and pieces of code at the moment but if anyone has an advice or ideas on any part of it I would massively appreciate it.
import ketai.camera.*;
import processing.video.*;
KetaiCamera cam;
PImage prev;
float threshold = 25;
float motionX = 0;
float motionY = 0;
float lerpX = 0;
float lerpY = 0;
void setup() {
//screen size of phone
size(2560, 1440);
imageMode(CENTER);
orientation(LANDSCAPE);
prev = createImage(1920, 1080, RGB);
cam = new KetaiCamera(this, 1920, 1080, 24);
}
void draw() {
cam.loadPixels();
prev.loadPixels();
int count = 0;
float avgX = 0;
float avgY = 0;
loadPixels();
// Begin loop to walk through every pixel
for (int x = 0; x < cam.width; x++ ) {
for (int y = 0; y < cam.height; y++ ) {
int loc = x + y * cam.width;
// What is current color
color currentColor = cam.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float b1 = blue(currentColor);
color prevColor = prev.pixels[loc];
float r2 = red(prevColor);
float g2 = green(prevColor);
float b2 = blue(prevColor);
float d = distSq(r1, g1, b1, r2, g2, b2);
if (d < threshold*threshold) {
//stroke(255);
//strokeWeight(1);
//point(x, y);
avgX += x;
avgY += y;
count++;
pixels[loc] = color(255);
} else {
pixels[loc] = color(0);
}
}
}
updatePixels();
//println(mouseX, threshold);
}
float distSq(float x1, float y1, float z1, float x2, float y2, float z2) {
float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
return d;
}
void onCameraPreviewEvent()
{
cam.read();
}
// start/stop camera preview by tapping the screen
void mousePressed()
{
if (cam.isStarted())
{
cam.stop();
}
else
cam.start();
}
void keyPressed() {
if (key == CODED) {
if (keyCode == MENU) {
if (cam.isFlashEnabled())
cam.disableFlash();
else
cam.enableFlash();
}
}
}