예제 #1
0
 def process_frame(self, img):
     # Works in OpenCV 3 and OpenCV 2
     gray = np.float32(etai.rgb_to_gray(img))
     response = cv2.cornerHarris(
         gray, blockSize=self.block_size, ksize=self.aperture_size,
         k=self.k)
     response = cv2.dilate(response, None)
     corners = response > self.threshold * response.max()
     return _pack_keypoints(np.argwhere(corners))
예제 #2
0
    def process_frame(self, img):
        curr_frame = etai.rgb_to_gray(img)
        if self._prev_frame is None:
            # There is no previous frame for the first frame, so we set
            # it to the current frame, which implies that the flow for
            # the first frame will always be zero
            self._prev_frame = curr_frame

        # works in OpenCV 3 and OpenCV 2
        flow_cart = cv2.calcOpticalFlowFarneback(
            self._prev_frame, curr_frame, flow=None,
            pyr_scale=self.pyramid_scale, levels=self.pyramid_levels,
            winsize=self.window_size, iterations=self.iterations,
            poly_n=self.poly_n, poly_sigma=self.poly_sigma,
            flags=self._flags)
        self._prev_frame = curr_frame

        return flow_cart
예제 #3
0
def _perform_convolution(convolution_config):
    '''Performs convolution of an input image with a kernel specified
    by the configuration parameters, and writes the result to the
    path specified by "filtered_image".

    Args:
        convolution_config: the configuration file for the module
    '''
    kernel_type = convolution_config.parameters.kernel_type
    if kernel_type == "x_derivative":
        kernel = _create_x_derivative_kernel()
    elif kernel_type == "y_derivative":
        kernel = _create_y_derivative_kernel()
    elif kernel_type == "sobel_vertical":
        kernel = _create_sobel_vertical_kernel()
    elif kernel_type == "sobel_horizontal":
        kernel = _create_sobel_horizontal_kernel()
    else:
        # this will be the Gaussian kernel
        # (make sure to remove this comment!)
        kernel = _create_gaussian_kernel(
            convolution_config.parameters.gaussian_sigma)

    for data in convolution_config.data:
        in_img = etai.read(data.input_image)
        if convolution_config.parameters.image_type == "grayscale":
            in_img = etai.rgb_to_gray(in_img)
        else:
            # if the image should be a color image, convert the grayscale
            # image to color (simply converts the image into a 3-channel
            # image)
            if etai.is_gray(in_img):
                in_img = etai.gray_to_rgb(in_img)
        if convolution_config.parameters.image_max_range == 1:
            in_img = (in_img.astype(float)) / 255.0

        filtered_image = _convolve(kernel, in_img)
        if data.filtered_matrix:
            etau.ensure_basedir(data.filtered_matrix)
            np.savez(data.filtered_matrix, filtered_matrix=filtered_image)
        if data.filtered_image:
            etau.ensure_basedir(data.filtered_image)
            etai.write(filtered_image, data.filtered_image)
예제 #4
0
 def process_frame(self, img):
     # works in OpenCV 3 and OpenCV 2
     gray = etai.rgb_to_gray(img)
     return cv2.Canny(
         gray, threshold1=self.threshold1, threshold2=self.threshold2,
         apertureSize=self.aperture_size, L2gradient=self.l2_gradient)