def createHomography(): img1 = cv2.imread('Images/ITUMap.bmp') fn = "GroundFloorData/sunclipds.avi" cap = cv2.VideoCapture(fn) #load Tracking data _, img2 = cap.read() print SIGBTools.getHomographyFromMouse(img2, img1, 6)
def textureMapGroundFloor(): #create H_T_G from first frame of sequence texture = cv2.imread('Images/ITULogo.jpg') fn = "GroundFloorData/sunclipds.avi" sequence = cv2.VideoCapture(fn) running, frame = sequence.read() h_t_g, calibration_points = SIGBTools.getHomographyFromMouse(texture, frame, -4) print h_t_g #fig = figure() while running: running, frame = sequence.read() if not running: return #texture map h,w,d = frame.shape warped_texture = cv2.warpPerspective(texture, h_t_g,(w, h)) result = cv2.addWeighted(frame, .7, warped_texture, .3, 50) #display cv2.imshow("Texture Mapping", result) cv2.waitKey(1)
def showFloorTrackingData(): #Load videodata fn = "GroundFloorData/sunclipds.avi" cap = cv2.VideoCapture(fn) #load Tracking data running, imgOrig = cap.read() M=cv2.imread("images/ituMap.bmp") H,W,Z=M.shape writer = cv2.VideoWriter('Map.avi', cv.CV_FOURCC('D','I','V','3'), 10.0, (W,H), True) G=imgOrig dataFile = np.loadtxt('GroundFloorData/trackingdata.dat') m,n = dataFile.shape fig = figure() H,points=SIGBTools.getHomographyFromMouse(G, M, N=4) for k in range(m): running, imgOrig = cap.read() if(running): boxes= frameTrackingData2BoxData(dataFile[k,:]) boxColors = [(255,0,0),(0,255,0),(0,0,255)] Hp=displayTrace(H, dataFile, fig, m, boxes[2]) for i in range(0,1): print "THE POINTS: "+str(points) print "THE HOMOGRAPHY: "+str(H) print "PLOT COORDINATES: "+str(Hp[i][0])+" , "+str(Hp[i][1])+" , "+str(Hp[i][2]) cv2.circle(M,(int(Hp[i][0]),int(Hp[i][1])),1,(255,0,0),10) for k in range(0,3): aBox = boxes[k] cv2.rectangle(imgOrig, aBox[0], aBox[1], boxColors[k]) #cv2.circle(M,(int(Hp[1][0]),int(Hp[1][1])),2,(0,255,0),10) cv2.imshow("boxes",imgOrig); cv2.imshow("map", M) temp=M writer.write(temp) cv2.waitKey(1)
def texturemapGroundFloor(): """ Place the texture on every frame of the clip """ fn = 'data/GroundFloorData/SunClipDS.avi' cap = cv2.VideoCapture(fn) texture = cv2.imread('data/Images/ITULogo.jpg') texture = cv2.pyrDown(texture) mTex,nTex,t = texture.shape running, imgOrig = cap.read() mI,nI,t = imgOrig.shape H,Points = SIGBTools.getHomographyFromMouse(texture,imgOrig,-1) h,w,d = imgOrig.shape while(running): running, imgOrig = cap.read() if(running): h,w,d = imgOrig.shape overlay = cv2.warpPerspective(texture, H,(w, h)) M = cv2.addWeighted(imgOrig, 0.5, overlay, 0.5,0) cv2.imshow("Overlayed",M) cv2.waitKey(1)
def texturemapGroundFloor(SequenceInputFile): ''' get four points in the map and overview a logo on the sequence ''' sequence, I2, retval = getImageSequence(SequenceInputFile) I1 = cv2.imread('Images/ITULogo.jpg') H, Points = SIGBTools.getHomographyFromMouse(I1, I2, -4) # get 4 points from mouse input h, w, d = I2.shape if(retval): cv2.imshow("Overlayed Image", I2) print("SPACE: Run/Pause") print("Q or ESC: Stop") running = True while(retval): ch = cv2.waitKey(1) # video controls if(ch == 32): # Spacebar if(running): running = False else: running = True if ch == 27: break if(ch == ord('q')): break if(running): retval, I2 = sequence.read() if(retval): # if there is an image overlay = cv2.warpPerspective(I1, H, (w, h)) # get the perspective image for overlaying on the video M = cv2.addWeighted(I2, 0.5, overlay, 0.5, 0) # overlay the video with the image cv2.imshow("Overlayed Image", M) # show the result
def simpleTextureMap(): I1 = cv2.imread('Images/ITULogo.jpg') I2 = cv2.imread('Images/ITUMap.bmp') cv2.namedWindow("Overlayed Image") #Print Help H,Points = SIGBTools.getHomographyFromMouse(I1,I2,4) h, w,d = I2.shape overlay = cv2.warpPerspective(I1, H,(w, h)) M = cv2.addWeighted(I2, 0.5, overlay, 0.5,0) cv2.imshow("Overlayed Image",M) cv2.waitKey(0)
def simpleTextureMap(): I1 = cv2.imread('Images/ITULogo.jpg') I2 = cv2.imread('Images/ITUMap.bmp') #Print Help H,Points = SIGBTools.getHomographyFromMouse(I1,I2,4) h, w,d = I2.shape overlay = cv2.warpPerspective(I1, H,(w, h)) M = cv2.addWeighted(I2, 0.5, overlay, 0.5,0) cv2.imshow("Overlayed Image",M) cv2.waitKey(0)
def texturemapGroundFloor(): I1 = cv2.imread('Images/ITULogo.jpg') cap = cv2.VideoCapture("GroundFloorData/sunclipds.avi") running, I2 = cap.read() H, points = SIGBTools.getHomographyFromMouse(I1,I2,-4) h, w, d = I2.shape overlay = cv2.warpPerspective(cv2.transpose(I1), H,(w, h)) while(running): M = cv2.addWeighted(I2, 1.0, overlay, 0.5,0) cv2.imshow("Texture", M) cv2.waitKey(1) running, I2 = cap.read() return
def texturemapGroundFloor(): I1 = cv2.imread("Images/ITULogo.jpg") cap = cv2.VideoCapture("GroundFloorData/sunclipds.avi") running, I2 = cap.read() H, points = SIGBTools.getHomographyFromMouse(I1, I2, -4) h, w, d = I2.shape overlay = cv2.warpPerspective(cv2.transpose(I1), H, (w, h)) while running: M = cv2.addWeighted(I2, 1.0, overlay, 0.5, 0) cv2.imshow("Texture", M) cv2.waitKey(1) running, I2 = cap.read() return
def texturemapGroundFloor(): sequence = projectResources + "GroundFloorData/sunclipds.avi" texture = cv2.imread(projectResources + 'Images/ITULogo.jpg') sequence = cv2.VideoCapture(sequence) texture = texture.copy() running, firstFrame = sequence.read(); H, points = SIGBTools.getHomographyFromMouse(texture,firstFrame,-4) h, w, d = firstFrame.shape overlay = cv2.warpPerspective(cv2.transpose(texture), H,(w, h)) while(True): if(running): running, cap = sequence.read() M = cv2.addWeighted(cap, 1.0, overlay, 0.5,0) cv2.imshow("Texture", M) cv2.waitKey(1) return
def texturemapGroundFloor(G,S,N): fn = "GroundFloorData\SunClipDS.avi" cap = cv2.VideoCapture(fn) running, imgOrig = cap.read() cv2.namedWindow("output") #temp remove G = imgOrig to change G = imgOrig for i in S: S = cv2.imread(i) H,Points = SIGBTools.getHomographyFromMouse(G,S,N) h, w,d = S.shape overlay = cv2.warpPerspective(G, H,(w, h)) M = cv2.addWeighted(S, 0.5, overlay, 0.5,0) cv2.imshow("output", M) cv2.imshow("output",imgOrig) cv2.waitKey(0)
def simpleTextureMap(): sequence = cv2.VideoCapture("GroundFloorData/SunClipDS.avi") retval, I1 = sequence.read() # I1 = cv2.imread('Images/ITULogo.jpg') I2 = cv2.imread('Images/ITUMap.bmp') # Print Help H, Points = SIGBTools.getHomographyFromMouse(I1, I2, 4) print(H) h, w, d = I2.shape overlay = cv2.warpPerspective(I1, H, (w, h)) M = cv2.addWeighted(I2, 0.5, overlay, 0.5, 0) cv2.imshow("Overlayed Image", M) cv2.waitKey(0)