Print RGB color-array
in
Programming Questions
•
11 months ago
Hi there,
Im trying to make a program that makes a 16x16 matrix from a selected part of my capturing webcam. After that the program "pixelates" it and gets the average color.
Output:" [0] -1479261 / [1] 207713 / [2] 278041 ..."
I seperate the average color array to three seprerate arrays (R+G+B). Now I want to print the RGB-Values from these arrays (red [255] / green [255] / blue [255]).
But I'm only getting strange values printed.
Output:" [I@4c9d22fc / [I@6063f5af / [I@4296e599 ").
Can you tell me how to print the three arrays after each other (red [0] / green [0] / blue[0]; red [1] / green [1] / blue [1];...red [255] / green [255] / blue [255]) to match them if their are even right?
Im trying to make a program that makes a 16x16 matrix from a selected part of my capturing webcam. After that the program "pixelates" it and gets the average color.
Output:" [0] -1479261 / [1] 207713 / [2] 278041 ..."
I seperate the average color array to three seprerate arrays (R+G+B). Now I want to print the RGB-Values from these arrays (red [255] / green [255] / blue [255]).
But I'm only getting strange values printed.
Output:" [I@4c9d22fc / [I@6063f5af / [I@4296e599 ").
Can you tell me how to print the three arrays after each other (red [0] / green [0] / blue[0]; red [1] / green [1] / blue [1];...red [255] / green [255] / blue [255]) to match them if their are even right?
- int xposp = 0;
- int yposp = 0;
- //evtl ausklammern falls andere version funktioniert
- //int farbevar = 0;
- int colorwert = 0;
- // Maus-Positons Variablen / 4x x,y
- int[] pointed = new int[8];
- //Video Import
- import processing.video.*;
- Capture cam;
- void setup (){
- size (1280, 960, P2D);
- // Variable Kameraliste
- String[] cameras = Capture.list();
-
- // Kameraliste erstellen
- 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]);
- }
-
- // Kamera initalisieren und wiedergeben
- // Im Array aus Liste --> list():
- cam = new Capture(this, cameras[37]);
- cam.start();
- }
- }
- // Bekomme Mausposition
- void mousePressed(){
- xposp = mouseX;
- yposp = mouseY;
-
- // Setzte Mauspositionswerte in Array
- if (pointed[0] == 0) {
- pointed[0] = xposp;
- pointed[1] = yposp;
- }
- else if (pointed[2] == 0 ) {
- pointed[2] = xposp;
- pointed[3] = yposp;
- }
- else if (pointed[4] == 0 ) {
- pointed[4] = xposp;
- pointed[5] = yposp;
- }
- else{
- pointed[6] = xposp;
- pointed[7] = yposp;
- }
- }
- void draw() {
- cursor(CROSS);
-
- // Gebe Mausklickwerte aus
- //println(pointed);
-
- // Kamera ausgeben
- if (cam.available() == true) {
- cam.read();
- }
- image(cam, 0, 0);
-
- // Variabele für Startposition Bricks
- int firstpixelx = 0;
- int firstpixely = 0;
- // Variable eine Brickgröße
- int bricky = 0;
- int brickx = 0;
-
- int langex = 0;
- int langey = 0;
-
- // Nach Markieren wird längere X-Kante wird ausgewählt
- if (pointed[6] - pointed[0] >= pointed[4] - pointed[2]) {
- langex = pointed[6] - pointed[0];
- }
- else { langex = pointed[4] - pointed[2];
- }
-
- // Nach Markieren wird längere Y-Kante wird ausgewählt
- if (pointed[3] - pointed[1] >= pointed[5] - pointed[7]) {
- langey = pointed[3] - pointed[1];
- }
- else { langey = pointed[5] - pointed[7];
- }
-
- // mittlerer Abstand erster Pixel von links
- // mittlerer Abstand erster Pixel von oben
- firstpixelx = (langex / 32) + pointed[2];
- firstpixely = (langey / 32) + pointed[1];
- // Errechnung Brickgröße x + y
- brickx = (langex / 16);
- bricky = (langey / 16);
-
- //println(firstpixelx + "," + firstpixely + "/" + brickx + "," + bricky);
-
- int[] pixelpx = new int[256];
- int[] pixelpy = new int[256];
- int kx = 0;
- int ky = 0;
- int i = 0;
- while (ky <= 15) {
- while (kx <= 15) {
- pixelpx[i] = firstpixelx + (brickx * kx);
- pixelpy[i] = firstpixely + (bricky * ky);
- i = i+1;
- kx = kx + 1;
- }
-
- kx = 0;
- ky = ky + 1;
- }
- //println(pixelpx);
-
- color aktcolor = get(pointed[0], pointed[1]);
- //println(aktcolor);
-
- /*
- color aktcolor = get(pixelpx, pixelpy);
- println(aktcolor);
- */
-
- // Farbwert genauer bestimmen
- // Variable Farbsumme
- int colorsum = 0;
- // Variable Farbmittelwert
- int[] colormittel = new int [256];
-
- // Hilfsvariable um Pixel drumrum zu erstellen
- int[] bx = new int[2];
- int[] by = new int[2];
- int k = 0;
-
- i = 0;
-
- // Nehme Mittelpunkt des Arrays und schreibe jeweils 10px drumrum
- // Hole Farbewerte und bilde den Mittelwert der Farbe
- while (i <= 255) {
- k = 0;
- colorsum = 0;
- bx[k] = pixelpx [i] - (brickx/2) + 10;
- by[k] = pixelpy [i] - (bricky/2) + 10;
- k = k + 1;
- bx[k] = pixelpx [i] + (brickx/2) - 10;
- by[k] = pixelpy [i] + (bricky/2) - 10;
- ky = by[0];
- while ( ky <= by [1] ) {
- kx = bx [0];
- while (kx <= bx[1]) {
- color colorwert = get(kx,ky);
- colorsum = colorsum + colorwert;
- kx = kx + 1;
- }
- ky = ky + 1;
- }
- colormittel[i] = colorsum / ((bx[1]-bx[0]) * (by[1]-by[0]));
- i = i + 1;
- }
- //println(colormittel);
-
-
- //Wandelt colormittel in RGB-Output um
- int ii = 0;
- int[] red = new int [256];
- int[] green = new int [256];
- int[] blue = new int [256];
-
- while (ii <= 255) {
- color c = color(colormittel[ii]);
- red [ii] = (c >> 16) & 0xFF;
- green [ii] = (c >> 8) & 0xFF;
- blue [ii] = c & 0xFF;
-
- ii = ii +1;
- }
- println(red + "/" + green + "/" + blue);
- }
1