def toGrayscale(self, isOriginalImage):
        """ Convert image to grayscale

            @param isOriginalImage: The value for choose original or processing Image
        """
        img = self.imageService.openImage(isOriginalImage)
        if img is None:
            return

        methodTimer = time.time()
        colorModel.rgbToYuv(img.load(), img.size)
        colorModel.yuvToGrayscaleRgb(img.load(), img.size)
        logFile = '{}/temp/log/toGrayscale.log'.format(self.appDir)
        with open(logFile, "a+") as text_file:
            text_file.write("Timer: {}\n".format(time.time() - methodTimer))
        imageComparison.calculateImageDifference(None, logFile)
        img.save('{}/temp/processingImage.png'.format(self.appDir))
        self.histogramService.saveHistogram(img=img, model='RGB')
Exemple #2
0
def dir_thresh(image, thresh=(0, np.pi/2)):
    gray = colorModel.rgbToYuv(image, gray.shape)
    gray = colorModel.yuvToGrayscaleRgb(gray, gray.shape)
    gaussianImg = img.copy()
    gaussianDeviation = 1.0 ##############################################
    gaussianFilterSize = math.floor(gaussianDeviation*3.0)
    filters.gaussianBlur('RGB', 0, gaussianImg.load(),
                gaussianImg.size, (gaussianFilterSize, gaussianFilterSize))
    edgeDetection.canny('RGB', 0, img.load(), img.size,
        gaussianImg.load(), 1, thresh)

    dir_threshold = np.zeros_like(gray)
    dir_threshold[(gray > thresh[0]) & (gray < thresh[1])] = 1

    return dir_threshold
Exemple #3
0
def mag_thresh(image, thresh=(1, 5)):
    gray = colorModel.rgbToYuv(image, gray.shape)
    gray = colorModel.yuvToGrayscaleRgb(gray, gray.shape)
    gaussianImg = img.copy()
    gaussianDeviation = 1.0 ##############################################
    gaussianFilterSize = math.floor(gaussianDeviation*3.0)
    filters.gaussianBlur('RGB', 0, gaussianImg.load(),
                gaussianImg.size, (gaussianFilterSize, gaussianFilterSize))
    edgeDetection.canny('RGB', 0, img.load(), img.size,
        gaussianImg.load(), 1, thresh)

    scaled_magnitude = np.uint8(255*gray_magnitude/np.max(gray_magnitude))

    mag_thresh = np.zeros_like(scaled_magnitude)
    mag_thresh[(scaled_magnitude > thresh[0]) & (scaled_magnitude < thresh[1])] = 1

    return mag_thresh
Exemple #4
0
    def detect(self, frame):
        #img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        colorModel.rgbToYuv(frame, frame.shape)
        colorModel.yuvToGrayscaleRgb(frame, frame.shape)

        roiy_end = frame.shape[0]
        roix_end = frame.shape[1]

        img = Image.fromarray(
            numpy.asarray(numpy.clip(frame, 0, 255), dtype="uint8"))
        img.show()
        roi = frame[self.road_horizon:roiy_end, 0:roix_end]
        print(roi)
        #blur = cv2.medianBlur(roi, 5)
        blur = numpy.copy(frame)
        filters.medianFilter('RGB', 0, blur, blur.shape, (5, 5))
        # contours = cv2.Canny(blur, 60, 120)

        contours = numpy.copy(blur)
        gaussianData = numpy.copy(blur)
        gaussianDeviation = 1.0  ##############################################
        gaussianFilterSize = math.floor(gaussianDeviation * 3.0)
        filters.gaussianBlur('RGB', 0, gaussianData, gaussianData.shape,
                             (gaussianFilterSize, gaussianFilterSize))
        edgeDetection.canny('RGB',
                            0,
                            contours,
                            contours.shape,
                            gaussianData,
                            amplifier=1.0,
                            threshold=(60, 120))

        # if self.prob_hough:
        #     lines = cv2.HoughLinesP(contours, 1, numpy.pi/180, self.vote, minLineLength=30, maxLineGap=100)
        # else:
        lines = self._standard_hough(contours, self.vote)

        if lines is not None:
            # find nearest lines to center
            lines = lines + numpy.array([
                0, self.road_horizon, 0, self.road_horizon
            ]).reshape(
                (1, 1, 4)
            )  # scale points from ROI coordinates to full frame coordinates
            left_bound = None
            right_bound = None
            for l in lines:
                # find the rightmost line of the left half of the frame and the leftmost line of the right half
                for x1, y1, x2, y2 in l:
                    theta = numpy.abs(numpy.arctan2(
                        (y2 - y1), (x2 - x1)))  # line angle WRT horizon
                    if theta > self.roi_theta:  # ignore lines with a small angle WRT horizon
                        dist = self._base_distance(x1, y1, x2, y2,
                                                   frame.shape[1])
                        if left_bound is None and dist < 0:
                            left_bound = (x1, y1, x2, y2)
                            left_dist = dist
                        elif right_bound is None and dist > 0:
                            right_bound = (x1, y1, x2, y2)
                            right_dist = dist
                        elif left_bound is not None and 0 > dist > left_dist:
                            left_bound = (x1, y1, x2, y2)
                            left_dist = dist
                        elif right_bound is not None and 0 < dist < right_dist:
                            right_bound = (x1, y1, x2, y2)
                            right_dist = dist
            if left_bound is not None:
                left_bound = self._scale_line(left_bound[0], left_bound[1],
                                              left_bound[2], left_bound[3],
                                              frame.shape[0])
            if right_bound is not None:
                right_bound = self._scale_line(right_bound[0], right_bound[1],
                                               right_bound[2], right_bound[3],
                                               frame.shape[0])

            return [left_bound, right_bound]