Esempio n. 1
0
 def __init__(self):
     self.showCamView = True
     self.showTopView = False
     self.screenIsFound = False
     self.captureLaser = False
     self.cam = OpenCV_Cam()
     self.screenFinder = ScreenFinder()
Esempio n. 2
0
class LaserScanner(object):
    def __init__(self):
        self.showCamView = True
        self.showTopView = False
        self.screenIsFound = False
        self.captureLaser = False
        self.cam = OpenCV_Cam()
        self.screenFinder = ScreenFinder()

    def findScreen(self):
        self.screenFinder.clear_found()
        while not self.screenIsFound:
            img = self.cam.read()
            self.screenFinder.find_screen_img(img)
            cv2.imshow('camera image', img)
            k = cv2.waitKey(5)
            if k == 27:
                break
        
        cv2.destroyWindow('camera image')

    def setScreenImage(self, bgImage): 
        self.screenFinder.set_screen_img(bgImage)
        self.background = bgImage

    def capture(self):
        if self.captureLaser:
            img = self.cam.read()
            Xcam = self.getLaserLocation(img)
            print Xcam
            #x, y = tuple(self.screenFinder.reverse_transform(Xcam).reshape(-1))
            return Xcam
        

    def update(self):
        self.img = self.cam.read()
        print self.capture()

    def show(self):
        cv2.imshow('Burn this image', self.background)
        if self.showTopView:
            top_view = sf.screen_top_view(img)
            cv2.imshow('Top view', top_view)
        if self.showCamView:
            cv2.imshow('Cam view', self.img)
        

    @staticmethod
    def getLaserLocation(image):
        red_part = image[:,:,2]
        ly, lx = np.unravel_index(red_part.argmax(), red_part.shape)
        return np.array([lx, ly])
Esempio n. 3
0
    ly, lx = np.unravel_index(max_pos, red_part.shape)
    if red_part[ly, lx] < threshold:
        return None
    return np.array([lx, ly])

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()
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:
Esempio n. 4
0
        return None
    return np.array([lx, ly])


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()
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: