def projectDown(image): proj = [] for x in range(image.width): col = cv.GetCol(image, x) sum = cv.Sum(col) proj.append(sum) return proj
def findX(imgSrc): mini = 0 maxi = 0 minFound = 0 maxVal=cv.RealScalar(imgSrc.width * 255) for i in range(0,imgSrc.width): data = cv.GetCol(imgSrc, i); val = cv.Sum(data); if(val[0] < maxVal[0]): maxi = i if(not minFound): mini = i minFound= 1 return mini,maxi
def getpositions(im): leftmost = 0 rightmost = 0 topmost = 0 bottommost = 0 temp = 0 for i in range(im.width): col = cv.GetCol(im, i) if cv.Sum(col)[0] != 0.0: rightmost = i if temp == 0: leftmost = i temp = 1 for i in range(im.height): row = cv.GetRow(im, i) if cv.Sum(row)[0] != 0.0: bottommost = i if temp == 1: topmost = i temp = 2 return (leftmost, rightmost, topmost, bottommost)
def getpositions(im): ''' this function returns leftmost,rightmost,topmost and bottommost values of the white blob in the thresholded image''' leftmost = 0 rightmost = 0 topmost = 0 bottommost = 0 temp = 0 for i in range(im.width): col = cv.GetCol(im, i) if cv.Sum(col)[0] != 0.0: rightmost = i if temp == 0: leftmost = i temp = 1 for i in range(im.height): row = cv.GetRow(im, i) if cv.Sum(row)[0] != 0.0: bottommost = i if temp == 1: topmost = i temp = 2 return (leftmost, rightmost, topmost, bottommost)
def main(): tree = utils.open_project(sys.argv) if tree == None: return try: os.mkdir(OUTPUT_DIR_NAME) except OSError: pass movie = tree.getroot() file_path = movie.attrib["path"] cap = cv.CreateFileCapture(file_path) cv.QueryFrame(cap) # skip frames in the beginning, if neccessary start_frame = int(movie.attrib["start_frame"]) for i in range(start_frame): cv.QueryFrame(cap) f = open("shots.txt", "r") lines = [line for line in f if line] f.close() t = time.time() w = None h = None #for line in f: for nr, line in enumerate(lines): print(nr + 1), "/", len(lines) #frame_from, frame_to, width, scene_nr = [int(i) for i in line.split("\t")] #width, scene_nr = [int(i) for i in line.split("\t")][2:] start_frame, end_frame, width = [ int(splt) for splt in line.split("\t") ] #width *= STRETCH_FAKTOR faktor = None output_img = None for frame_counter in range(width): #if frame_counter % STRETCH_FAKTOR == 0: # img = cv.QueryFrame(cap) # if not img: # break img = cv.QueryFrame(cap) if not img: break if nr == 0: w = img.width h = img.height if frame_counter == 0: faktor = float(w) / float(width) output_img = cv.CreateImage((width, h), cv.IPL_DEPTH_8U, 3) col_nr = faktor * (frame_counter + 0.5) col_nr = int(math.floor(col_nr)) #print frame_counter, width, col_nr, w col = cv.GetCol(img, col_nr) for i in range(h): cv.Set2D(output_img, i, frame_counter, cv.Get1D(col, i)) #return cv.SaveImage( os.path.join(OUTPUT_DIR_NAME, "shot_slitscan_%03d_%d.png" % (nr + 1, start_frame)), output_img) print "%.2f min" % ((time.time() - t) / 60) #raw_input("- done -") return