Example #1
0
from cam import OpenCV_Cam
import cv2
import os.path
import time

cam = OpenCV_Cam(0)
cam.size = (1920, 1080)

KEY_ESC = 27
KEY_SPACE = ord(' ')
PAGE_DOWN = 2228224 # This make the stop motion to be controllable by presenter. 
prevFrame = None
i = 0 


#Make a directory on current working directory with date and time as its name
timestr = time.strftime("%Y%m%d-%H%M%S")
cwd = os.getcwd()
dirName = cwd + "\\"+timestr 
os.makedirs(dirName)


fname= cwd + "\\frame_.png"
if os.path.isfile(fname):
    prevFrame = cv2.imread(fname)


#Make .avi file from collected frames
fourcc = cv2.cv.CV_FOURCC(*'XVID')
video = cv2.VideoWriter(dirName+"\\"+'output_.avi',fourcc, 3.0, cam.size, isColor =True)
Example #2
0
        return img

    def reverse_transform(self, cam_pts):
        pts = np.float32(cam_pts).reshape(-1, 1, 2)
        return cv2.perspectiveTransform(pts, self.cam2screen_matrix)

    def screen_top_view(self, cam_img):
        shape = (self._screen_img.shape[1], self._screen_img.shape[0])
        img = cv2.warpPerspective(cam_img, self.cam2screen_matrix, shape)
        return img


if __name__ == '__main__':
    sf = ScreenFinder()
    cam = OpenCV_Cam()
    cam.size = (640, 480)

    color_img = cv2.imread('wood.png')
    img = cv2.cvtColor(color_img, cv2.COLOR_BGR2GRAY)
    cv2.imshow('source', color_img)

    sf.set_screen_img(img)
    if img.shape[0] * img.shape[1] > cam.size[0] * cam.size[1]:
        img = cv2.resize(img, cam.size)

    while True:
        cam_img = cam.read()

        if not sf.screen_is_found:
            sf.find_screen_loop(cam, True)
Example #3
0
def find_threshold(cam):
    img = cam.read()
    hx, hy = find_laser_loc(img, 0)
    threshold = img[hy, hx, 2] + 10
    print "The red threshold is automatically determined to be", threshold
    return threshold

background = cv2.imread('wood.png')
cv2.imshow('Burn this page!', background)

sf = ScreenFinder()
sf.set_screen_img(background)

cam = OpenCV_Cam()
cam.size = 640, 480
img = cam.read()
sf.find_screen_img(img)
sf.find_screen_loop(cam, False)

bs = background.shape
canvas = np.full((bs[0], bs[1], 4), 0, dtype=np.uint8)

# prepare threshold
thresh = find_threshold(cam)

show_top_view, show_cam_view = False, False
while True:
    img = cam.read()
    
    if show_cam_view:
Example #4
0
from cam import OpenCV_Cam
import cv2
import os.path
import time

cam = OpenCV_Cam(0)
cam.size = (1920, 1080)

KEY_ESC = 27
KEY_SPACE = ord(' ')
PAGE_DOWN = 2228224  # This make the stop motion to be controllable by presenter.
prevFrame = None
i = 0

#Make a directory on current working directory with date and time as its name
timestr = time.strftime("%Y%m%d-%H%M%S")
cwd = os.getcwd()
dirName = cwd + "\\" + timestr
os.makedirs(dirName)

fname = cwd + "\\frame_.png"
if os.path.isfile(fname):
    prevFrame = cv2.imread(fname)

#Make .avi file from collected frames
fourcc = cv2.cv.CV_FOURCC(*'XVID')
video = cv2.VideoWriter(dirName + "\\" + 'output_.avi',
                        fourcc,
                        3.0,
                        cam.size,
                        isColor=True)
Example #5
0
    img = cam.read()
    hx, hy = find_laser_loc(img, 0)
    threshold = img[hy, hx, 2] + 10
    print "The red threshold is automatically determined to be", threshold
    return threshold


FILENAME = 'wood_800.png'
background = cv2.imread(FILENAME)
cv2.imshow('Burn this page!', background)

sf = ScreenFinder()
sf.set_screen_img(background)

cam = OpenCV_Cam()
cam.size = 640, 480
img = cam.read()
sf.find_screen_img(img)
sf.find_screen_loop(cam, False)

bs = background.shape
canvas = np.full((bs[0], bs[1], 4), 0, dtype=np.uint8)

# prepare threshold
thresh = find_threshold(cam)

show_top_view, show_cam_view = False, False
while True:
    img = cam.read()

    if show_cam_view:
    def reverse_transform(self, cam_pts):
        pts = np.float32(cam_pts).reshape(-1,1,2)
        return cv2.perspectiveTransform(pts, self.cam2screen_matrix)
    
    
    def screen_top_view(self, cam_img):
        shape = (self._screen_img.shape[1], self._screen_img.shape[0])
        print self.cam2screen_matrix
        img = cv2.warpPerspective(cam_img, self.cam2screen_matrix, shape)
        return img


if __name__ == '__main__':
    sf = ScreenFinder()
    cam = OpenCV_Cam()
    cam.size = (640, 480)
    
    color_img = cv2.imread('wood.png')
    img = cv2.cvtColor(color_img, cv2.COLOR_BGR2GRAY)
    cv2.imshow('source', color_img)

    sf.set_screen_img(img)
    if img.shape[0] * img.shape[1] > cam.size[0] * cam.size[1]:
        img = cv2.resize(img, cam.size)

    while True:
        cam_img = cam.read()
        
        if not sf.screen_is_found:
            sf.find_screen_loop(cam, True)