def get_training_set_classification(self, n, rstart, cstart, rend, cend): training_data = [] for r in range(rstart, rend, 10): if (r % 100 == 0): print("Training sample", int((r - rstart) * 100 / (rend - rstart)), "percent complete") for c1 in range(cstart, cend, 10): (res, disp) = load_pfm.lookupL(r, c1, self.arr0, self.arr1) corr_pixel = c1 - disp if res == 2: c3 = int(corr_pixel) c4 = c3 + 1 training_data.append( (1, self.build_Feature_Vector(r, c1, r, c3, n))) training_data.append( (1, self.build_Feature_Vector(r, c1, r, c4, n))) for c2 in range(cstart, c1, 50): if abs(c1 - c2 - disp) < 1.0: training_data.append( (1, self.build_Feature_Vector(r, c1, r, c2, n))) else: training_data.append( (0, self.build_Feature_Vector(r, c1, r, c2, n))) print("Training sample loaded") return training_data
def get_training_set_regression(self, n): training_data = [] for r in range(800, 1400, 10): if (r % 100 == 0): print("Training sample", int((r - 800) / 6), "percent complete") for c1 in range(800, 1400, 10): (res, disp) = load_pfm.lookupL(r, c1, self.arr0, self.arr1) corr_pixel = c1 - disp if res == 2: c3 = int(corr_pixel) c4 = c3 + 1 training_data.append( (disp, self.build_Feature_Vector(r, c1, r, c3, n))) training_data.append( (disp, self.build_Feature_Vector(r, c1, r, c4, n))) # training_data.append((c1, c3, disp, self.build_Feature_Vector(r, c1, r, c3, n))) # training_data.append((c1, c4, disp, self.build_Feature_Vector(r, c1, r, c4, n))) for c2 in range(800, c1, 50): training_data.append( (disp, self.build_Feature_Vector(r, c1, r, c2, n))) # training_data.append((c1, c2, disp, self.build_Feature_Vector(r,c1, r, c2, n))) print("Training sample loaded") return training_data
def getCandidates(self, r, c): candidates = [] lef = self.lefts[r - rstart][c1 - cstart] for dis in range(0, 300): righ = self.rights[r - rstart][(cend - 1 - c) + dis] feature_vector = np.abs(lef - righ) (res, disp) = load_pfm.lookupL(r, c, self.arr0, self.arr1) candidates.append((c, r, dis, feature_vector)) return candidates
def getCandidates(r, c): candidates = [] lef = loader.lefts[r-rstart][c-cstart] (res, disp) = load_pfm.lookupL(r, c, loader.arr0, loader.arr1) if res == 2: img3_arr[r-rstart,c-cstart] = disp for dis in range(0,300): righ = loader.rights[r-rstart][(cend - 1 - c) + dis] feature_vector = np.abs(lef - righ) #print(disp) candidates.append((c, r, dis, feature_vector)) return candidates
pixels = loader.img_lookup(loader.Left_Pixels, c + cstart, r+rstart) img2_arr[r,c] = 0.299 * pixels[0] + 0.587 * pixels[1] + 0.114*pixels[2] pixels = loader.img_lookup(loader.Right_Pixels, c + cstart - best_disps[r,c], r + rstart) img4_arr[r,c] = 0.299 * pixels[0] + 0.587 * pixels[1] + 0.114*pixels[2] #calculate stats and create output images total = 0 total_within1 = 0 total_within2 = 0 total_within5 = 0 meansquare = 0.0 for r in range(rend-rstart): for c in range(cend-cstart): (res, disp) = load_pfm.lookupL(r + rstart, c + cstart, loader.arr0, loader.arr1) if res == 2: err = abs(disp - img_arr[r,c]) if err <= 1: total_within1 += 1 if err <= 2: total_within2 += 1 if err <= 5: total_within5 += 1 meansquare += err **2 total += 1 print("within 1:", total_within1 / total) print("within 2:", total_within2 / total) print("within 5:", total_within5 / total) print("mean square error:", math.sqrt(meansquare / total))