Horn Schunck Optischer Fluss

Mr. Pink

Mitglied
Hey Leute,

meine Aufgabe ist es aus zwei Standbildern ein Optischen Fluss abzuzeichnen. Ich habe hier die Horn-Schunck Methode angepackt. leider funkt die nicht so wie sie sollte. Vlt. hab ich gewisse Dinge auch falsch verstanden um jeglichen Tipp bin ich Dankbar. Also wenn sich einer damit auskennt. Codeausschnitte auf Interesse.

Vielen Dank. Grüße
 
Zuletzt bearbeitet:

Mr. Pink

Mitglied
Also ich hab hier, die gemittelte Intensitätsberechnung der Pixel vom Bild:

Java:
//Führe die Intensitätsberechnung der Pixel durch
		for (int x = 1; x < width - 1; x++) {
			for (int y = 1; y < height - 1; y++) {
				//System.out.println(col);
				Ix(x, y, inImage, OpticalFlow.bf2);
				Iy(x, y, inImage, OpticalFlow.bf2);
				It(x, y, inImage, OpticalFlow.bf2);
				uarr[0]=0;
				varr[0]=0;
			}
		}



//Variablen / Methoden des OpticalFlow
		//Berechne Ix
		public static float[] Ix(int x, int y,  BufferedImage inImage, BufferedImage t1) {
			Ix[x] = 1/4 * (getColor(inImage, x, y+1) - getColor(inImage, x,y) + getColor(t1, x, y+1) - getColor(t1, x, y) + getColor(inImage, x+1, y+1) - getColor(inImage, x+1, y) + getColor(t1, x+1, y+1) - getColor(t1, x+1, y));
			
			return Ix;
		}
		//Berechne Iy
		public static float[] Iy(int x, int y, BufferedImage inImage, BufferedImage t1) {
			Iy[y] =  1/4 * (getColor(inImage, x+1, y) - getColor(inImage, x,y) + getColor(t1, x+1, y) - getColor(t1, x, y) + getColor(inImage, x+1, y+1) - getColor(inImage, x, y+1) + getColor(t1, x+1, y+1) - getColor(t1, x, y+1));
			
			return Iy;
		}	
		//Berechne It
		public static float[] It(int x, int y,  BufferedImage inImage, BufferedImage t1) {
			It[x] =  1/4 * (getColor(t1, x, y+1) - getColor(inImage, x,y) + getColor(t1, x+1, y) - getColor(inImage, x+1, y) + getColor(t1, x, y+1) - getColor(inImage, x, y+1) + getColor(t1, x+1, y+1) - getColor(inImage, x+1, y+1));
			
			return It;
		}


Und hier wird durch die Intensität der Pixel mit der Horn-Schunckformel die Vektoren berechnet:
Java:
//Berechne die Optischen Vektoren
		float lambda=10;
		int iteration=10;
		for(int iter=1; iter <= iteration; iter++) {
			for (int x = 1; x < width - 1; x++) {
				for (int y = 1; y < height - 1; y++) {
					uarr[x]= uarr[x-1] - (( Ix[x]*uarr[x-1] + Iy[y]*varr[y-1] + It[x] ) / (lambda*(Ix[x]*Ix[x]) + (Iy[y]*Iy[y])))*Ix[x];
					varr[y]= varr[y-1] - (( Ix[x]*uarr[x-1] + Iy[y]*varr[y-1] + It[x] ) / (lambda*(Ix[x]*Ix[x]) + (Iy[y]*Iy[y])))*Iy[y];
				}
			}
		}

leider hab ich noch ein fehler in der Berechnung der Vektoren, wenn ich das Vektor-Array in der Console ausgebe habe ich nur Nullen im Array. Wobei das dass kleinste Problem ist, da ich nicht genau weis ob das überhaupt der richtige Ansatz dafür ist. bzw. wie soll ich die zwei Arrays denn am Schluss als Bild ausgeben !?
 

Neue Themen


Oben