Пример #1
0
    def draw_zones(self, frame, width, height):
        # Re-initialize zones in case they have not been initalized
        if self.zones is None:
            self.zones = tools.get_zones(width, height, pitch=self.pitch)

        for zone in self.zones:
            cv2.line(frame, (zone[1], 0), (zone[1], height), BGR_COMMON['orange'], 1)
Пример #2
0
	def normalize(self, frame, pitch=0):

		width = frame.shape[1]
		height = frame.shape[0]
		zones = tools.get_zones(width, height, pitch=pitch)
		y_points = [4.8 * height / 6, 3 * height / 6,  1.2 * height / 6]
		bounds = np.array([[zones[i][0], zones[i][1], 2 * height/3, height] for i in range(0, 4)])
		bounds = np.append(bounds, np.array([[zones[i][0], zones[i][1], height / 3, 2 * height / 3] for i in range(0, 4)]), axis=0)
		bounds = np.append(bounds, np.array([[zones[i][0], zones[i][1], 0, height / 3 ] for i in range(0, 4)]), axis=0)

		if self.options['calibrate']:

			mids = np.array([((zones[i][0] + zones[i][1]) / 2) for i in range(0, 4)])
			sectors = np.array([[x_co, y_co] for y_co in y_points for x_co in mids ])
			sectors_values = np.array([self.get_avg(frame, 5, sec[0], sec[1]) for sec in sectors])

			calibration = {}
			avg_overall = np.mean([[self.get_avg(frame, 8, x_co, y_co)] for x_co in mids for y_co in y_points], axis=0)
			calibration['avg'] = avg_overall[0].tolist()
			calibration['sectors'] = sectors.tolist()
			calibration['sectors_values'] = sectors_values.tolist()
			self.write_json_avg(calibration, pitch)
		else:
			calibration_get = self.get_json_calibration(pitch)
			sectors = np.array(calibration_get['sectors'])
			sectors_values = np.array(calibration_get['sectors_values'])
			avg_overall = np.array(calibration_get['avg'])

		for i in range(0, len(sectors)):
			frame[bounds[i][2]:bounds[i][3], bounds[i][0]:bounds[i][1]] -= (sectors_values[i] - avg_overall)

		return frame