Video output scaled to 2 x resolution
in
Programming Questions
•
3 years ago
EDIT: Let me break this down a bit.
Hello all!
I am trying to upscale a webcam stream using JMyron. I have noticed that processing copes badly with higher resolution input, so Instead I want the input scaled up twice the size so it fills up a little more of the screen. Is there an easy way I am missing here, or do I work on the more manual version down below, currently it does not work.
I though a 2x scale algorithm could be interesting to see on live footage, and it doesn't add many lines of code. But alas I am just getting a grey rectangle it is the right size (twice the capture resolution) but no video. I think I am making some error on the display side of things, the math seems right. Here is the code:
Hello all!
I am trying to upscale a webcam stream using JMyron. I have noticed that processing copes badly with higher resolution input, so Instead I want the input scaled up twice the size so it fills up a little more of the screen. Is there an easy way I am missing here, or do I work on the more manual version down below, currently it does not work.
I though a 2x scale algorithm could be interesting to see on live footage, and it doesn't add many lines of code. But alas I am just getting a grey rectangle it is the right size (twice the capture resolution) but no video. I think I am making some error on the display side of things, the math seems right. Here is the code:
- import JMyron.*;
JMyron m;
int camWidth = 320; //capture resolution
int camHeight = 240;
void setup(){
size(640,480); // size is twice the capture res
m = new JMyron();
m.start(camWidth,camHeight);
m.findGlobs(0);
println("Myron " + m.version());
}
void draw(){
m.update();//update the camera
int[] img = m.image(); //get frame of the camera
int B,D,E,F,H,E0,E1,E2,E3;
loadPixels();
/*
this is my implementation of super2x it uses a 9x9 grid around the pixel
A | B | C |
D | E | F |
G | H | I |
where E is expanded to four pixels
E0 | E1
E2 | E2
based on the relation between different diagonals: B-F, F-H, H-D, D-B
see: http://scale2x.sourceforge.net/algorithm.html for full detials
*/
for(int i=0;i<camWidth*camHeight;i++){ //loop through all the captured pixels
E = color(img[i]);
// checks if given pixel is at an edge and if so fills the of edge pixel with E's value.
B = i < camWidth ? E : color(img[i-camWidth]);// pixel above E
D = i < 1 ? E : color(img[i-1]);// pixel to the left of E
F = i > camWidth * camHeight - 1 ? E : color(img[i+1]);// pixel to the right of E
H = i > camWidth * camHeight - camWidth ? E : color(img[i+camWidth]);// pixel below E
// checks for diagonal relations
if (B != H && D != F){
E0 = D == B ? D : E;
E1 = B == F ? F : E;
E2 = D == H ? D : E;
E3 = H == F ? F : E;
// if there are none regular scaling occurs
} else {
E0 = E;
E1 = E;
E2 = E;
E3 = E;
}
for (int j=0;1<width*height;j++){ // expands the read pixels in to 2 x scale
pixels[(i*2)] = E0;
pixels[(i*2+1)] = E1;
pixels[(i*2+width)] = E2;
pixels[(i*2+width+1)] = E3;
}
}
updatePixels();
}
public void stop(){
m.stop();//clean up
super.stop();
}
1