Skip to content

Commit

Permalink
video
Browse files Browse the repository at this point in the history
  • Loading branch information
batKem committed Jun 8, 2018
1 parent 5c1e784 commit 02739e5
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 67 deletions.
57 changes: 34 additions & 23 deletions Game/Game.pde
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import gab.opencv.*;


import processing.video.*;

float depth = 2000.0;
float fovy = PI/3.0;
ImageProcessing imgproc;
Expand Down Expand Up @@ -28,15 +33,25 @@ PGraphics scorePanel;
PGraphics scrollBarPanel;


Movie m;

Mover ball;

void settings() {
size(1000, 1000, P3D);
}

void setup() {
OpenCV opencv = new OpenCV(this, 100, 100);

m= new Movie(this, "testvideo.avi");
m.loop();

boardX = 600;
boardY = 600;

//To call webcam
imgproc = new ImageProcessing();
imgproc = new ImageProcessing(m);
String []args = {"Image processing window"};
PApplet.runSketch(args, imgproc);
delay(3500);
Expand All @@ -56,15 +71,14 @@ void setup() {
scoreText = createGraphics((int)(height*0.1),(int)(height*0.18),P2D);
scorePanel = createGraphics((int)(height*0.68),(int)(height*0.15),P2D);

ball =new Mover();
ball =new Mover(boardX, boardY);
gravityForce= new PVector();
gravityConstant = -0.8;

cylinders= new ArrayList<PVector>();
cylinder = loadShape("cylinder.obj");

boardX = 1000;
boardY = 1000;


shiftMode=false;
}
Expand All @@ -91,21 +105,21 @@ void draw() {



PVector rots= imgproc.getRotation();
PVector rots= imgproc.getRotation(m.get());

if (rots != null){
System.out.println("Printing R.x" + rots.x);
System.out.println(rots);

//I think it shouldnt be += but =
rx= rots.x;
// rx+= radians((mouseX-pmouseX)*rotationScale) ;
rz= rots.y; //In Week12 - 2 its said that we have to use x & y, no mention for z
rz= rots.z; //In Week12 - 2 its said that we have to use x & y, no mention for z
// rz+= radians(-(mouseY-pmouseY)*rotationScale);


//bounderies
rx = min(1,max(rx,-1)); //60º == 1 radian
rz = min(1,max(rz,-1));
rx = min(radians(60),max(rx,radians(-60)));
rz = min(radians(60),max(rz,radians(-60)));
}
else
System.out.println("nulllll");
Expand Down Expand Up @@ -245,8 +259,8 @@ void run(PGraphics s){

s.pushMatrix();
s.fill(255,255,255);
float x = map(v.x, -500.0,500.0, 0.0, height*0.18);
float z = map(v.z, -500.0,500.0, 0.0, height*0.18);
float x = map(v.x, -boardX/2.0,boardX/2.0, 0.0, height*0.18);
float z = map(v.z, -boardY/2.0,boardY/2.0, 0.0, height*0.18);
s.ellipse(x,z, s.width*cylinderScale.x/(boardX/2),s.height*cylinderScale.z/(boardY/2));
s.popMatrix();
}
Expand Down Expand Up @@ -341,26 +355,23 @@ void mouseWheel(MouseEvent event) {
}

void mouseDragged(){

/*
if (!shiftMode && mouseY < width*0.8){
PVector rots= imgproc.getRotation();
if (rots != null){
System.out.println("Printing R.x" + rots.x);
rx= rots.x;
rz= rots.z;
// rx+= radians((mouseX-pmouseX)*rotationScale) ;
rx+= radians((mouseX-pmouseX)*rotationScale) ;
//bounderies
rx = min( radians(60),max(rx,radians(-60)));
// rz+= radians(-(mouseY-pmouseY)*rotationScale);
rz+= radians(-(mouseY-pmouseY)*rotationScale);
rz = min( radians(60),max(rz,radians(-60)));
}
else
System.out.println("nulllll");
}*/


}

}
29 changes: 16 additions & 13 deletions Game/Mover.pde
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ class Mover{
float Y_MAX=200;
float Y_MIN = -200;

final float radius =50;
float cylinderRadius = 100;
final float radius =10;
float cylinderRadius = 20;
float boardX,boardY;

Mover(){
location =new PVector(0, 0,0);
Mover(float boardX, float boardY){
location =new PVector(0, 40,0);
velocity= new PVector(0,0,0);
this.boardX = boardX;
this.boardY = boardY;
}

void update(){
Expand All @@ -27,24 +30,24 @@ class Mover{
void display2D(PGraphics s, float dimension){
//s.translate(location.x, location.y, location.z);

float x = map(location.x, -500.0,500.0, 0.0, dimension);
float z = map(location.z, -500.0,500.0, 0.0, dimension);
float x = map(location.x, -boardX/2.0,boardX/2.0, 0.0, dimension);
float z = map(location.z, -boardY/2.0,boardY/2.0, 0.0, dimension);

s.ellipse(x, z, radius*dimension/500, radius*dimension/500);
s.ellipse(x, z, radius*dimension/(boardX/2.0), radius*dimension/(boardX/2.0));
}

void checkEdges(int[] score){

if(location.x > 500) {
if(location.x > boardX/2.0) {
score[0] -= (int)norm(velocity);
velocity.x *= -0.5;
} else if(location.x < -500) {
} else if(location.x < -boardY/2.0) {
score[0] -= (int)norm(velocity);
velocity.x *= -0.5;
} if(location.z > 500) {
} if(location.z > boardX/2.0) {
score[0] -= (int)norm(velocity);
velocity.z *= -0.5;
} else if(location.z < -500) {
} else if(location.z < -boardY/2.0) {
score[0] -= (int)norm(velocity);
velocity.z *= -0.5;
}
Expand All @@ -53,8 +56,8 @@ class Mover{
/*fixing a bug where the ball keeps falling out of range because
its speed kept being multiplied by -1 which led to negative speed values being
positive ones since gravity adds up*/
location.x = max(-500,min(location.x,500));
location.z = max(-500,min(location.z,500));
location.x = max(-boardX/2.0,min(location.x,boardX/2.0));
location.z = max(-boardY/2.0,min(location.z,boardY/2.0));
}

PVector rawNormal(PVector p){
Expand Down
2 changes: 1 addition & 1 deletion Game/QuadGraph.pde
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,4 @@ class CWComparator implements Comparator<PVector> {
return -1;
else return 1;
}
}
}
68 changes: 38 additions & 30 deletions Game/app.pde
Original file line number Diff line number Diff line change
@@ -1,53 +1,40 @@
import java.util.*;
import gab.opencv.*;

import processing.video.*;

class ImageProcessing extends PApplet {

OpenCV opencv;
Capture cam;

Movie cam;
PImage img;
ArrayList<Integer> bestCandidates;

public ImageProcessing(Movie m){

this.cam = m;
}

void settings() {
size(640, 480);
}

void setup() {
opencv = new OpenCV(this, 100, 100);

String[] cameras = Capture.list();


if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
//If you're using gstreamer0.1 (Ubuntu 16.04 and earlier),
//select your predefined resolution from the list:
cam = new Capture(this, cameras[0]);
//If you're using gstreamer1.0 (Ubuntu 16.10 and later),
//select your resolution manually instead:
//cam = new Capture(this, 640, 480, cameras[0]);
cam.start();
}

cam.loop();


}

void draw(){
//Camera

if (cam.available() == true)
cam.read();
img = cam.get();
image(img, 0, 0);
//Camera
}

public PVector getRotation(){
public PVector getRotation(PImage img){
List<PVector> lines, corners;
QuadGraph qGraph = new QuadGraph();
TwoDThreeD twoDThreeD = new TwoDThreeD(img.width, img.height, 30);
Expand All @@ -60,15 +47,16 @@ void settings() {
lines = hough(img, 4); //Hough transform

corners = qGraph.findBestQuad(lines, img.width, img.height, 280000, 30000, false);

if (corners.size() != 0){
corners = qGraph.sortCorners((ArrayList<PVector>)corners);
for (int j = 0; j < corners.size(); j++)
corners.get(j).z = 1.;

PVector rotations = twoDThreeD.get3DRotations(corners);

rotations.x = normalDegrees(rotations.x);
rotations.y = normalDegrees(rotations.y);
rotations.y = normalDegrees(rotations.y);
rotations.z = normalDegrees(rotations.z);

return rotations;
Expand All @@ -87,6 +75,26 @@ void settings() {
else
return (float) n;
}
/*
ArrayList<PVector> clockWhiseSort(ArrayList<PVector> corners){
PVector corner1 = corners.get(0);
PVector corner2 = corners.get(2);
PVector midCorner = new PVector( (corner1.x+corner2.x)/2.0, (corner1.y+corner2.y)/2.0 );
Collections.sort(corners, new CWComparator(midCorner));
PVector origin =new PVector(0, 0);
float distance = 1000;
for (PVector corner :corners){
distance = (corner.dist(origin)< distance)? corner.dist(origin):distance;
}
while(corners.get(0).dist(origin) != distance){
Collections.rotate(corners,1);
}
return corners;
}*/

List<PVector> hough(PImage edgeImg, int nLines) {

Expand Down Expand Up @@ -493,4 +501,4 @@ void settings() {
}
}

}
}
Binary file removed Game/data/board1.jpg
Binary file not shown.
Binary file added Game/data/testvideo.avi
Binary file not shown.
Binary file added Week03/vid/data/testvideo.avi
Binary file not shown.
Binary file added Week03/vid/testvideo.avi
Binary file not shown.
19 changes: 19 additions & 0 deletions Week03/vid/vid.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import processing.video.*;
Movie myMovie;

void setup() {
size(200, 200);
myMovie = new Movie(this, "testvideo.avi");
myMovie.loop();
}
/*
void draw() {
tint(255, 20);
image(myMovie, mouseX, mouseY);
}
// Called every time a new frame is available to read
void movieEvent(Movie m) {
m.read();
}
*/

0 comments on commit 02739e5

Please sign in to comment.