示例#1
0
    def draw_final(self, frame, paper_detection, hand_detection):
        hand_masked = image_analysis.apply_hist_mask(frame,
                                                     hand_detection.hand_hist)
        paper_hand = paper_detection.paper_copy()
        self.plot_word_boxes(paper_hand, paper_detection.words)

        contours = image_analysis.contours(hand_masked)
        if contours is not None and len(contours) > 0:
            max_contour = image_analysis.max_contour(contours)
            hull = image_analysis.hull(max_contour)
            centroid = image_analysis.centroid(max_contour)
            defects = image_analysis.defects(max_contour)

            if centroid is not None and defects is not None and len(
                    defects) > 0:
                farthest_point = image_analysis.farthest_point(
                    defects, max_contour, centroid)

                if farthest_point is not None:
                    self.plot_farthest_point(frame, farthest_point)
                    self.plot_hull(frame, hull)
                    # self.plot_contours(frame, contours)
                    # self.plot_defects(frame, defects, max_contour)
                    # self.plot_centroid(frame, (cx,cy))

                    self.plot_farthest_point(paper_hand, farthest_point)
                    point = self.original_point(farthest_point)
                    paper_detection.update_pointed_locations(point)
                    self.text = paper_detection.get_most_common_word()

        self.plot_text(paper_hand, self.text)
        frame_final = np.vstack([paper_hand, frame])
        return frame_final
示例#2
0
	def draw_final(self, frame, paper_detection, hand_detection):
		hand_masked = image_analysis.apply_hist_mask(frame, hand_detection.hand_hist)
		paper_hand = paper_detection.paper_copy()
		self.plot_word_boxes(paper_hand, paper_detection.words)

		contours = image_analysis.contours(hand_masked)
		if contours is not None and len(contours) > 0:
			max_contour = image_analysis.max_contour(contours)
			hull = image_analysis.hull(max_contour)
			centroid = image_analysis.centroid(max_contour)
			defects = image_analysis.defects(max_contour)

			if centroid is not None and defects is not None and len(defects) > 0:	
				farthest_point = image_analysis.farthest_point(defects, max_contour, centroid)

				if farthest_point is not None:
					self.plot_farthest_point(frame, farthest_point)
					self.plot_hull(frame, hull)
					# self.plot_contours(frame, contours)
					# self.plot_defects(frame, defects, max_contour)
					# self.plot_centroid(frame, (cx,cy))

					self.plot_farthest_point(paper_hand, farthest_point)
					point = self.original_point(farthest_point)
					paper_detection.update_pointed_locations(point)
					self.text = paper_detection.get_most_common_word()
		
		self.plot_text(paper_hand, self.text)		
		frame_final = np.vstack([paper_hand, frame])
		return frame_final
示例#3
0
	def draw_final(self, frame, paper_detection, hand_detection):
		hand_masked = image_analysis.apply_hist_mask(frame, hand_detection.hand_hist)
		# paper_hand = paper_detection.paper_copy()
		# self.plot_word_boxes(paper_hand, paper_detection.words)

		contours = image_analysis.contours(hand_masked)
		if contours is not None and len(contours) > 0:
			max_contour = image_analysis.max_contour(contours)
			hull = image_analysis.hull(max_contour)
			centroid = image_analysis.centroid(max_contour)
			defects = image_analysis.defects(max_contour)

			if centroid is not None and defects is not None and len(defects) > 0:	
				farthest_point = image_analysis.farthest_point(defects, max_contour, centroid)

				if farthest_point is not None:
					self.plot_farthest_point(frame, farthest_point)
					self.plot_hull(frame, hull)

					point = self.original_point(farthest_point)
					self.farthest_point = farthest_point
					# print(farthest_point)
					x, y = farthest_point
					y -= 400

					# a,b are the top-left coordinate of the rectangle and (c,d) be its width and height.
					# to judge a point(x0,y0) is in the rectangle, just to check
					# if a < x0 < a+c and b < y0 < b + d

					for i in range(9):
						#if farthest_point is in any of the rectangles
						#then we add that to string
						#self.hand_col_nw[i], self.hand_row_nw[i] a, b
						#self.hand_col_se[i],self.hand_row_se[i] c, d

						# # if i == 0:
						# print(i)
						# print(self.hand_col_nw[i], self.hand_row_nw[i])
						# print(self.hand_col_se[i],self.hand_row_se[i])
						# print(x, y)
						# print("=================")

						if self.hand_col_nw[i] < x and x < self.hand_col_se[i] and self.hand_row_nw[i] < y and y < self.hand_row_se[i]:
							print self.pw, i
							if len(self.pw) < 1 or self.pw[-1] != str(i):
								self.pw += str(i)
		
		frame_final = frame
		return frame_final
 def get_paper(self, frame):
     paper_masked = image_analysis.apply_hist_mask(frame, self.paper_hist)
     contours = image_analysis.contours(paper_masked)
     max_contour = image_analysis.max_contour(contours)
     paper = image_analysis.contour_interior(frame, max_contour)
     return paper
示例#5
0
	def get_paper(self, frame):
		paper_masked = image_analysis.apply_hist_mask(frame, self.paper_hist)
		contours = image_analysis.contours(paper_masked)
		max_contour = image_analysis.max_contour(contours)
		paper = image_analysis.contour_interior(frame, max_contour)
		return paper