User:Chen Junyu/Prototyping/Lens based/Trim2/KINECT: Difference between revisions
Chen Junyu (talk | contribs) No edit summary |
Chen Junyu (talk | contribs) No edit summary |
||
Line 111: | Line 111: | ||
kinect.deRegisterUser(curContext, userId); | kinect.deRegisterUser(curContext, userId); | ||
} | } | ||
<code> | <code> |
Revision as of 20:40, 13 April 2014
"Grandma"
- SUMMARY
The first idea of the kinect project is to get photos of Chinese women born in the same year -1929 in different age as resource to make sequence scrubber . There are two reasons why I choose this year : one is that it was the year which my grandma born, and she passed away in the beginning of this year, therefore I took her photo as the last one in the sequence-which means the end of their generation ; another reason is as women born in late 20s, they have totally different experience as ours -- the Republic of China era to the People's Republic of China era, the the Great Leap Forward and 10-year cultural revolution ,most of them suffered at the first half of their life. To get these photos , I use Wiki Category to trace people born in the certain year . But there is a problem , the women I found from wiki , most of them are celebrities who live in the upper class . Since their face reflects their state of mind and events they encountered, the samples I got probably are too invariable. I would like to get more multifarious samples ,so I tried another way to search. By using Flickr as the target resource website, I got women's photos in different ages by keywords [ ages , grandma ] such as (30s, grandma) . The results I got here are much meaningful than using Wiki Category.
- DISADVANTAGE
The results I got from Flickr were not so precise-their birth years were uncern , probably from 1910s to 1950s. The bigger time span lead the topic of this project to a more vague situation.
- Video
- Code
The code controls kinect to play certain photo by the distance between the position people stand to the camera.
import SimpleOpenNI.*;
import java.awt.Color;
import java.util.Iterator;
SingleUserKinect kinect;
PVector userPosRealWorld = new PVector(); // 3d user position
boolean USE_KINECT = false;
float comZ; // Center of Mass Z
//CHENJUNYU, change the values below according to the distance you want to use
float minZ = 100;
float maxZ = 2500;
//CHENJUNYU, change the value below depending on how many image files you have
int numImages = 44; // total number of images
PImage[] images = new PImage[numImages]; // the images will be stored in this list
// setup is executed once, when the program started
void setup() {
// size of the window
//size(400,400);// use size "(displayWidth, displayHeight)" for fullscreen
//size(displayWidth, displayHeight);
size(256,256);//CHENJUNYU, change the values here too. Don't use values that are too big or you'll have performance issues. You can also try using size(displayWidth, displayHeight); (just uncomment the line above and comment this one)
// set frame background to black (this is the background you'll see in Present Mode)
frame.setBackground(new Color(0, 0, 0));
// load the image sequence
loadImageSequence();
// user SingleUserKinect for tracking.
kinect = new SingleUserKinect(this);
}
// draw is repeatedly executed, as fast as possible, or according to frameRate setting
void draw() {
// update user position
kinect.update();
// set center of mass to the maximum value
float comZ = maxZ;
// if we are tracking a user, get the position of his Center of Mass
if (kinect.trackedUserId != 0) {
kinect.getCoM(userPosRealWorld);
comZ = userPosRealWorld.z;
if (comZ > maxZ) {
comZ = maxZ;
}
else if (comZ < minZ) {
comZ = minZ;
}
}
// map x position to an image in the sequence
float maxRange = maxZ - minZ; // total range
int slice_size = (int)maxRange/images.length; //1000 / 100 = 10
float z = map(comZ, minZ, maxZ, 0, maxRange); // map center of mass to a positive range
int slice = (int)(z / slice_size); //0 / 10 = 0
if (slice >= numImages) slice = numImages-1;
println("slice " + slice);
// draw the image
image(images[slice], 0, 0, width, height);
}
// load the image sequence
void loadImageSequence() {
String filename = "";
for (int i = 0; i < numImages; i++) {
//CHENJUNYU, change the filename according to the ones you have. I put my files inside folder data/export.
filename = "headtrack/" +nf(i, 3) + ".jpg";
images[i] = loadImage(filename);
}
}
// -----------------------------------------------------------------
// SimpleOpenNI user events
// -----------------------------------------------------------------
// onNewUser is triggered when the kinect registers a new user
void onNewUser(SimpleOpenNI curContext, int userId)
{
// let our SingleUserKinect Class take care of this
kinect.registerNewUser(curContext, userId);
}
// onLostUser is triggered when the kinect deregisters a user
void onLostUser(SimpleOpenNI curContext, int userId)
{
// let our SingleUserKinect Class take care of this
kinect.deRegisterUser(curContext, userId);
}