I’m afraid the warpImage of the TPS is too heavy for my 640x480 camera feed. I can do about 3 frames per second on quite a decent computer.
import cv2
import numpy as np
cam = cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_EXPOSURE,-6)
cam_points = np.loadtxt("data/cam_points.txt", dtype=int).reshape(1,-1,2)
screen_points = np.loadtxt("data/screen_points.txt", dtype=int).reshape(1,-1,2)
screen_points = (screen_points * (480/2400, 640/3200) + (-64,0)).astype(int) # 3200 = 640*480/480 to maintain aspect ratio, -64 to restore center
matches = [cv2.DMatch(i, i, 0) for i,_ in enumerate(screen_points[0])]
tps = cv2.createThinPlateSplineShapeTransformer()
tps.estimateTransformation(screen_points, cam_points, matches)
tps.applyTransformation(cam_points)
while True:
ret, src = cam.read()
dst = tps.warpImage(src)
for cam_point, screen_point in zip(cam_points[0],screen_points[0]):
cv2.circle(src, cam_point, 4, (0,0,255), thickness=-1)
cv2.circle(dst, screen_point, 4, (0,255,0), thickness=-1)
cv2.imshow("src",src)
cv2.moveWindow("src",0,0)
cv2.imshow("dst",dst)
cv2.moveWindow("dst",640,0)
key = cv2.waitKey(1)
if key==27:
break
cv2.destroyAllWindows()
So now I’m looking into cv::remap. I checked the tutorials but I don’t get it yet how to pre-calculate maps forcv::remap()
for my case… I will keep trying and reading. If you have any suggestions please let me know.