Пример #1
0
    def getEmbedDetections(self, src, pipParams=None):
        img = self.imgProcessor.undistort(src=src)
        vBoxes, heatMap = self.scanner.getRelevantBoxes(src=img)
        binary = self.preProcess(src=img)
        currFitLeft, leftFitType, leftBin = self.lineLeft.getFit(src=binary)
        currFitRight, rightFitType, rightBin = self.lineRight.getFit(src=binary)
        sanityPass = self.sanityCheckPass(currFitLeft, currFitRight)

        if sanityPass:
            img = self.addLanePoly(srcShape=binary.shape, dst=img, fitLeft=currFitLeft, fitRight=currFitRight)
        else:
            if self.lineLeft.reScanJustified():
                currFitLeft, leftFitType, leftBin = self.lineLeft.reScanWithPrimary(src=binary)
            else:
                self.lineLeft.resetFits()
                currFitLeft, leftFitType, leftBin = self.lineLeft.getFit(src=binary)
            if self.lineRight.reScanJustified():
                currFitRight, rightFitType, rightBin = self.lineRight.reScanWithPrimary(src=binary)
            else:
                self.lineRight.resetFits()
                currFitRight, rightFitType, rightBin = self.lineRight.getFit(src=binary)
            sanityPass = self.sanityCheckPass(currFitLeft, currFitRight)
            if sanityPass:
                img = self.addLanePoly(srcShape=binary.shape, dst=img, fitLeft=currFitLeft, fitRight=currFitRight)

        aux.drawBoxes(img=img, bBoxes=vBoxes)
        origin = (20, 20)

        if pipParams is not None:
            alpha = pipParams['alpha']
            ratio = pipParams['scaleRatio']
            commonBin = cv2.addWeighted(src1=leftBin, alpha=0.5, src2=rightBin, beta=0.5, gamma=1.0)
            pipHeight = int(commonBin.shape[0] * ratio)
            heatWidth = int(heatMap.shape[1] * ratio)
            self.addPip(pipImage=commonBin, dstImage=img,
                        pipAlpha=alpha, pipResizeRatio=ratio, origin=origin)

            self.addPip(pipImage=heatMap, dstImage=img,
                        pipAlpha=alpha, pipResizeRatio=ratio,
                        origin=(img.shape[1] - heatWidth - 20, 20))

            if currFitLeft is not None and currFitRight is not None:

                self.addOffsetStamp(leftFit=currFitLeft, rightFit=currFitRight,
                                    image=img, origin=(20, pipHeight + 70), fontScale=0.66, thickness=2,
                                    color=(0, 255, 0))
        return img
    def embedDetections(self, src, pipParams=None):
        """
        Main 'pipeline' for adding Lane polygon AND detected vehicles to the original image
        :param src: original image
        :param pipParams: alpha and scale ratios
        :return: undistorted color image with the Lane embedded.
        """

        # 1. Undistortion
        img = self.imgProcessor.undistort(src=src)

        """
        1a. ====| PROJECT 5 - VEHICLE DETECTION |====
        Getting vehicle boxes
        """
        vBoxes, heatMap = self.scanner.relevantBoxes(src=img)

        # 2. Binary (bird-eye projection)
        '''
        binary = self.preProcess(src=img)

        # 3. Getting fits
        #currFitLeft, leftFitType, leftBin = self.lineLeft.getFit(src=binary)
        #currFitRight, rightFitType, rightBin = self.lineRight.getFit(src=binary)

        # 4. Evaluation
        sanityPass = self.sanityCheckPass(currFitLeft, currFitRight)

        if sanityPass:
            # Adding Lane polygon if sanity check passed
            img = self.addLanePoly(srcShape=binary.shape, dst=img, fitLeft=currFitLeft, fitRight=currFitRight)
        else:

            # Evaluation if box-search re-scan justified without resetting history of previous fits
            if self.lineLeft.reScanJustified():
                currFitLeft, leftFitType, leftBin = self.lineLeft.reScanWithPrimary(src=binary)
            else:
                # Resetting fits and starting from scratch with box-search
                self.lineLeft.resetFits()
                currFitLeft, leftFitType, leftBin = self.lineLeft.getFit(src=binary)

            # Same for right fit.
            if self.lineRight.reScanJustified():
                currFitRight, rightFitType, rightBin = self.lineRight.reScanWithPrimary(src=binary)
            else:
                self.lineRight.resetFits()
                currFitRight, rightFitType, rightBin = self.lineRight.getFit(src=binary)

            # Evaluation after second search attempt
            # sanityPass, laneWidth = self.sanityCheckPass(currFitLeft, currFitRight)
            sanityPass = self.sanityCheckPass(currFitLeft, currFitRight)

            # Adding Lane polygon if sanity check passed. Otherwise, simply no poly added
            if sanityPass:
                img = self.addLanePoly(srcShape=binary.shape, dst=img, fitLeft=currFitLeft, fitRight=currFitRight)
        '''
        # ====| PROJECT 5 - VEHICLE DETECTION |====
        # Drawing vehicle boxes
        aux.drawBoxes(img=img, bBoxes=vBoxes)

        # Upper left corner where starting to add pip and telemetry
        origin = (20, 20)

        # Adding PIP
        if pipParams is not None:
            alpha = pipParams['alpha']
            ratio = pipParams['scaleRatio']

            # Combining bins from left and right fit searches
            #commonBin = cv2.addWeighted(src1=leftBin, alpha=0.5, src2=rightBin, beta=0.5, gamma=1.0)

            # To keep for subsequent telemetry stamps
            #pipHeight = int(commonBin.shape[0] * ratio)
            heatWidth = int(heatMap.shape[1] * ratio)

            # Lane Detection Picture-in-Picture
            '''
            self.addPip(pipImage=commonBin, dstImage=img,
                        pipAlpha=alpha, pipResizeRatio=ratio, origin=origin)
            '''

            # ====| PROJECT 5 - VEHICLE DETECTION |====
            # Vehicle Detection Picture-in-Picture
            self.addPip(pipImage=heatMap, dstImage=img,
                        pipAlpha=alpha, pipResizeRatio=ratio,
                        origin=(img.shape[1] - heatWidth - 20, 20))
            '''

            if currFitLeft is not None and currFitRight is not None:
                self.addCurvatureStamp(leftFit=currFitLeft, rightFit=currFitRight,
                                       image=img, origin=(20, pipHeight + 40), fontScale=0.66, thickness=2,
                                       color=(0, 255, 0))

                self.addOffsetStamp(leftFit=currFitLeft, rightFit=currFitRight,
                                    image=img, origin=(20, pipHeight + 70), fontScale=0.66, thickness=2,
                                    color=(0, 255, 0))
            '''
        return img