package association; import java.io.File; import javax.imageio.ImageIO; import descriptors.HoG; import parameters.tracking_arguments; import particlefiltering.observation; import particlefiltering.pHistogram; import tracking.Atributes; public class Probabilities { public double prob_app (Atributes A1, Atributes A2, tracking_arguments tracking_parameters, int frame, int boxi, int boxj, String image_name) { /*Consertar os parametros aqui*/ /*try { ImageIO.write(A1.image, "png", new File("./comparado/"+image_name+"_"+String.format("%02d", boxi)+"_"+String.format("%02d", boxj)+".A1.png")); //ImageIO.write(Original, "png", new File(out_path + String.format("%05d", iframe) + "/detection.png")); } catch (Exception e) { System.err.println("cannot store image"); } try { ImageIO.write(A2.image, "png", new File("./comparado/"+image_name+"_"+String.format("%02d", boxi)+"_"+String.format("%02d", boxj)+".A2.png")); //ImageIO.write(Original, "png", new File(out_path + String.format("%05d", iframe) + "/detection.png")); } catch (Exception e) { System.err.println("cannot store image"); }*/ pHistogram histo1 = new pHistogram(); HoG hog1 = new HoG(); //double[] e1 = hog1.HoGFixedNumberOfCells (A1.image, tracking_parameters.numCellsX, tracking_parameters.numCellsY, tracking_parameters.blockSize); //double[] e1 = hog1.HoGFixedNumberOfCells (A1.image, 2, 2, 2); double[] e1 = hog1.hog(A1.image, 5, 1, 1, 9, 32, false); histo1.alloc_vector(e1.length); for (int i = 0; i < e1.length; i++) { histo1.set_data(i, e1[i]); } observation obs = new observation(); obs.normalize_histogram(histo1); pHistogram histo2 = new pHistogram(); HoG hog2 = new HoG(); //double[] e2 = hog2.HoGFixedNumberOfCells (A2.image, tracking_parameters.numCellsX, tracking_parameters.numCellsY, tracking_parameters.blockSize ); //double[] e2 = hog2.HoGFixedNumberOfCells (A2.image, 2, 2, 2); double[] e2 = hog1.hog(A2.image, 5, 1, 1, 9, 32, false); histo2.alloc_vector(e2.length); for (int i = 0; i < e2.length; i++) { histo2.set_data(i, e2[i]); } obs.normalize_histogram(histo2); /* compute likelihood as e^{\lambda D^2(h, h^*)} */ double d_sq = obs.histo_dist_sq (histo1, histo2); return Math.exp (-tracking_parameters.sigma_app * d_sq); } public double prob_pos (Atributes A1, Atributes A2, tracking_arguments tracking_parameters) { double d = Math.sqrt ( ( A2.get_x() - A1.get_x() ) * ( A2.get_x() - A1.get_x() ) + ( A2.get_y() - A1.get_y() ) * ( A2.get_y() - A1.get_y() ) ); double sigma = tracking_parameters.sigma_pos; double prob = Math.exp (-(d*d)/(2*sigma*sigma)); return prob; } public double prob_size (Atributes A1, Atributes A2, tracking_arguments tracking_parameters) { //double s = Math.max(s1, s2)/Math.min(s1,s2); int s1 = A1.get_width() * A1.get_height(); int s2 = A2.get_width() * A2.get_height(); double s = (s1-s2)/s1; double sigma = tracking_parameters.sigma_size; double prob = Math.exp (-(s*s)/(2*sigma*sigma)); return prob; } }