Example #1
0
    def update_background(self, frame=None):
        if frame is None:
            frame = self.last_frame
            if frame is None:
                frame = self.grab_frame()
        self.background = clone_image(frame)

        self.background_gray = to_gray_image(self.background)
        self.background_flipped = flip_image(self.background)
Example #2
0
	def update_background(self, frame=None):
		if frame is None:
			frame = self.last_frame
			if frame is None:
				frame = self.grab_frame()
		self.background = clone_image(frame)
		
		self.background_gray = to_gray_image(self.background)
		self.background_flipped = flip_image(self.background)
Example #3
0
    def grab_frame(self):
        ret, frame = self.camera.read()
        frame_gray = to_gray_image(frame)
        frame_flipped = flip_image(frame)

        # Set the size of things if this is the first image we have seen
        if self.last_frame is None:
            self.size = frame.shape
            self.num_pixels = self.size[0]*self.size[1]

        self.recent_frames_gray.append(frame_gray)
        self.recent_frames.append(frame)
        if len(self.recent_frames) > self.recent_frames_max:
            del self.recent_frames[0]
            del self.recent_frames_gray[0]

        self.last_frame = clone_image(frame)
        self.last_frame_flipped = frame_flipped
        self.last_frame_gray = frame_gray
        return frame
Example #4
0
	def grab_frame(self):
		frame = cv.QueryFrame(self.camera)
		frame_gray = to_gray_image(frame)
		frame_flipped = flip_image(frame)

		# Set the size of things if this is the first image we have seen
		if self.last_frame is None:
			self.size = cv.GetSize(frame)
			self.num_pixels = self.size[0]*self.size[1]
	
		self.recent_frames_gray.append(frame_gray)
		self.recent_frames.append(frame)
		if len(self.recent_frames) > self.recent_frames_max:
			del self.recent_frames[0]
			del self.recent_frames_gray[0]

		self.last_frame = clone_image(frame)
		self.last_frame_flipped = frame_flipped
		self.last_frame_gray = frame_gray
		return frame 
Example #5
0
    def check_for_card(self):
        found = False
        base_corr = 0

        self.grab_frame()
        # if the user didn't set the background, get the first frame and consider it the background
        if self.background is None:
            print "Updating background on the account of it being None"
            self.update_background()

        history_diff = self.calc_biggest_diff()
        # Detect movement
        if history_diff < 0.9:
            self.has_moved = True

        # No movement now, but there was before
        elif self.has_moved == True:
            base_corr = self.calc_background_similarity()
            print base_corr
            # Looking at the background, false alarm
            # set the frame as the new background, this helps with lightning change
            if base_corr >= 0.95:
                #self.update_background()
                self.has_moved = False
            else:
                # background and current frame are < 25% similar
                warped = find_card(self.last_frame)
                if warped is not None:
                    self.snapshot = warped
                    # self.snapshot = flip_image(self.snapshot)
                    found = True
                    self.has_moved = False
                else:
                    self.has_moved = False

        self.display_background()
        self.display_live("%.4f [0-10 stable, >10 unstable] | %.4f [>0.75 is background, <0.75 contains foreground]" % (history_diff, base_corr))

        if found is True:
            return clone_image(self.snapshot)
        return None
Example #6
0
	def check_for_card(self):
		found = False
		base_corr = 0

		self.grab_frame()
		# if the user didn't set the background, get the first frame and consider it the background
		if self.background is None:
			print "Updating background on the account of it being NOne"
			self.update_background()
		
		history_diff = self.calc_biggest_diff()

		# Detect movement
		if history_diff > 10:
			self.has_moved = True

		# No movement now, but there was before
		elif self.has_moved == True:
			base_corr = self.calc_background_similarity()
			# Looking at the background, false alarm
			# set the frame as the new background, this helps with lightning change
			if base_corr >= 0.75:
				#self.update_background()
				self.has_moved = False
			else:
				# background and current frame are < 25% similar
				corners = detect_card(self.last_frame_gray, self.background_gray)
				if corners is not None:
					self.snapshot = get_card(self.last_frame_gray, corners)
					self.snapshot = flip_image(self.snapshot)
					found = True
					self.has_moved = False
				else:
					self.has_moved = False
		
		self.display_background()
		self.display_live("%.4f [0-10 stable, >10 unstable] | %.4f [>0.75 is background, <0.75 contains foreground]" % (history_diff, base_corr))

		if found is True:
			return clone_image(self.snapshot)
		return None
Example #7
0
	def display(self):
		tmp = clone_image(self.img)
		overlay_text_on_image(tmp, "%s - %s" % (self.card_name, self.set_name), self.font)
		cv.ShowImage("match", tmp)
		cv.ResizeWindow("match", 800, 600)