# HeadTracking Negative Space

**URL:** https://discourse.processing.org/t/headtracking-negative-space/4620
**Category:** Libraries
**Created:** [October 18, 2018, 11:15pm UTC](https://discourse.processing.org/t/headtracking-negative-space/4620 "2018-10-18T23:15:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Bianyx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bianyx/32/1995_2.png) [@Bianyx](https://discourse.processing.org/u/Bianyx)
#### Post date: [October 18, 2018, 11:15pm UTC](https://discourse.processing.org/t/headtracking-negative-space/4620/1 "2018-10-18T23:15:59Z")

</div>

Hey Guys,

So I am prototyping on processing.  
The effect I would want to achieve is same as the [https://www.youtube.com/watch?v=Jd3-eiid-Uw](http://video).  
Another reference  
[![](https://images.squarespace-cdn.com/content/5414cc37e4b06505bdaf2198/1519889066629-ETQOJCYSIQ5OEZDIOG3H/TheVoid_GIF_1.gif?content-type=image%2Fgif) ](https://images.squarespace-cdn.com/content/5414cc37e4b06505bdaf2198/1519889066629-ETQOJCYSIQ5OEZDIOG3H/TheVoid_GIF_1.gif?content-type=image%2Fgif)

I am using openCV for head tracking, it works.  
Now I am moving the camera position according to the head tracking position, the camera would not always be in front of my object. Like the pic, there is an angle if the camera is not in front of the camera.

What it should be is, if we look at the object through the camera from an angle, we should stay in front of the object, just cant not see all the sides.

So I realised, it is not just the position or rotation of the camera, it is relative space. I could link both camera position and camera centre to face tracking position to keep the camera stay in front of the object, but in that case the rendered object also moves.  
Here I have a simple draft I used Mouse Position to replace Head Tracking to simulate the problem.

```
void setup() {
size(1640, 1640, P3D);

}

void draw() {
clear();
background(255);

float x=map(mouseX,0,640,-320,320);
float y=map(mouseY,0,640,-320,320);

pushMatrix();
translate(width/2,height/2,0);
noFill();
strokeWeight(5);
box(323,323,323);
popMatrix();

//move both camera position and camera centre
camera(width/2+x, height/2.0+y, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0+x, height/2.0+y, 0, 0, 1, 0);
//move camera position only
// camera(width/2+x, height/2.0+y, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0);

println(mouseX);

}

```

And also the original code for the head tracking one if needed

```
import gab.opencv.*;
import processing.video.*;
import java.awt.*;

int rot1=0;
int rot2=0;
int rot3=0;
Capture video;
OpenCV opencv;
float smoothedrot1=0;
float smoothedrot2=0;
float smoothedrot3=0;

void setup() 
{
  fullScreen(P3D);
  frameRate(60);

  video = new Capture(this, 320, 240);
  opencv = new OpenCV(this, 320, 240);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();
  
}

void draw()
{
  clear();
  //scale(0.5);
  //translate(0,0,750);
  opencv.loadImage(video);
  image(video, 0, 0,0,0);
  noFill();
  Rectangle[] faces = opencv.detect();
  println(faces.length);
  for (int i = 0; i < faces.length; i++) 
  {
    rot1=(faces[i].x+faces[i].width/2)-opencv.width/2;
    rot2=(faces[i].y+faces[i].height/2)-opencv.height/2;
    rot3=faces[i].width+faces[i].height;
    println(rot1 + "," + rot2);
   }
  smoothedrot1=lerp(smoothedrot1,rot1,0.4);
  smoothedrot2=lerp(smoothedrot2,rot2,0.4);
  smoothedrot3=lerp(smoothedrot3,rot3,0.1);

  beginShape();
  //float i=0;
  //float y=map(i,-800,900,0,mouseX);
  camera(smoothedrot1*2, smoothedrot2*1, -200-740+smoothedrot3, 0.0, 0.0, 0.0, 0.0, 0.02, 0.0); 
 //camera(-400+y, mouseY, -740+smoothedrot3, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 

  rotateZ(PI);
  stroke(255,255,255);
  strokeWeight(15);
  fill(54,54,255);
  box(1440,900,2500);

  pointLight(255, 255, 255, -300, -300, -600);
  pointLight(255, 255, 255, 200, 200, -600);
  noStroke();
  fill(255,0,0);
  
  box(40,30,800);
  
  
      
 
 
  
}

```

---

<div class="post-metadata">

### Author: ![Bianyx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bianyx/32/1995_2.png) [@Bianyx](https://discourse.processing.org/u/Bianyx)
#### Post date: [October 19, 2018, 10:23pm UTC](https://discourse.processing.org/t/headtracking-negative-space/4620/2 "2018-10-19T22:23:38Z")

</div>

> [@Bianyx](#):
>
> Now I am moving the camera position according to the head tracking position, the camera would not always be in front of my object. Like the pic, there is an angle if the camera is not in front of the camera.
> 
> What it should be is, if we look at the object through the camera from an angle, we should stay in front of the object, just cant not see all the sides.
> 
> ![32](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2c4c948826de4f1e244e768dbcd79565db6b4b5e.jpeg)

 ![59](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2cc0f8ab1707bfa40f3a6e8322fd28085190588c.png)

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [October 23, 2018, 10:02pm UTC](https://discourse.processing.org/t/headtracking-negative-space/4620/3 "2018-10-23T22:02:32Z")

</div>



---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [October 23, 2018, 10:03pm UTC](https://discourse.processing.org/t/headtracking-negative-space/4620/4 "2018-10-23T22:03:58Z")

</div>

Apologies, for some reason (new user account post w links?) it looks like your discussion was unlisted by the system. I have listed it.

---

<div class="post-metadata">

### Author: ![danielgayo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/danielgayo/32/3263_2.png) [@danielgayo](https://discourse.processing.org/u/danielgayo)
#### Post date: [January 16, 2019, 9:15am UTC](https://discourse.processing.org/t/headtracking-negative-space/4620/5 "2019-01-16T09:15:21Z")

</div>

Hi,  
One student team has delivered this code to my as their project for a course.

I wonder if you could verify that this code is yours and who you are.

You can find me at [daniel.gayo@gmail.com](mailto:daniel.gayo@gmail.com).

Thanks, Dani

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [January 17, 2019, 8:25pm UTC](https://discourse.processing.org/t/headtracking-negative-space/4620/6 "2019-01-17T20:25:06Z")

</div>

@danielgayo – were you able to contact @Bianyx (or whoever you needed to) for this?

---

<div class="post-metadata">

### Author: ![danielgayo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/danielgayo/32/3263_2.png) [@danielgayo](https://discourse.processing.org/u/danielgayo)
#### Post date: [January 17, 2019, 9:12pm UTC](https://discourse.processing.org/t/headtracking-negative-space/4620/7 "2019-01-17T21:12:34Z")

</div>

I received no reply.

However I questioned the students and they admitted the plagiarism.

Thank you.
