Ejemplo n.º 1
0
    def raw1(self, img):
        self.counter += 1
        hBefore, wBefore, _ = img.shape
        img = self.transformer.resize(img, 0, 270, 40, 500)

        contrast = self.transform(img)
        rois = DetectionUtils.detectContours(contrast,
                                             widthLower=self.dim1Lower,
                                             widthUpper=self.dim1Upper,
                                             heightLower=self.dim2Lower,
                                             heigthUpper=self.dim2Upper)
        tracked, _ = self.tracker.track(rois)
        self.numObjects = self.tracker.N
        if self.guiMode:
            for roi in rois:
                ImgUtils.drawRect(roi, img)
                detectedCentroid = ImgUtils.findRoiCentroid(roi)
                ImgUtils.drawCircle(detectedCentroid, img, colour=(255, 0, 0))
            for objectId, centroid in tracked.items():
                ImgUtils.drawCircle((centroid[0], centroid[1]), img)
                ImgUtils.putText(coords=centroid,
                                 text=str(objectId % 1000),
                                 img=img,
                                 colour=(255, 0, 0))

        return img, contrast, []
Ejemplo n.º 2
0
    def brick0(self, img):
        # img = img[550:, 350:-400, :]
        img = img[100:, :, :]

        contrast = np.copy(img)
        contrast = self.transform(contrast)
        contours, h = cv2.findContours(contrast, cv2.RETR_EXTERNAL,
                                       cv2.CHAIN_APPROX_SIMPLE)
        rois = []
        for c in contours:
            approx = cv2.approxPolyDP(c, 0.01 * cv2.arcLength(c, True), True)
            x, y, w, h = cv2.boundingRect(c)
            if len(approx) < 1 or w < 130 or h < 60:
                continue
            x1 = x
            x2 = x1 + w
            y1 = y
            y2 = y1 + h
            if y1 < 250 or x2 < 100:
                continue
            rois.append([x1, y1, x2, y2])
            # targetHeight = 130
            # numParts = h // targetHeight
            # if numParts < 1:
            #     rois.append([x1, y1, x2, y2])
            # else:
            #     step = (h % targetHeight)
            #     y = y1
            #     for i in range(0, numParts):
            #         r = [x1, y, x2, y + targetHeight + step]
            #         y += (step + targetHeight)
            #         rois.append(r)

        tracked, _ = self.tracker.track(rois)
        self.numObjects = self.tracker.N
        if self.guiMode:
            for roi in rois:
                ImgUtils.drawRect(roi, img)
                detectedCentroid = ImgUtils.findRoiCentroid(roi)
                ImgUtils.drawCircle(detectedCentroid, img, colour=(255, 0, 0))
            for objectId, centroid in tracked.items():
                ImgUtils.drawCircle((centroid[0], centroid[1]), img)
                ImgUtils.putText(coords=centroid,
                                 text=str(objectId % 1000),
                                 img=img,
                                 colour=(255, 0, 0))

        return img, contrast, []
Ejemplo n.º 3
0
    def postbake1(self, img):
        hBefore, wBefore, _ = img.shape
        img = self.transformer.resize(img)
        origImg = np.copy(img)
        contrast = self.transform(img)
        rois, radii = DetectionUtils.houghDetect(contrast,
                                                 radiusMin=self.dim1Lower,
                                                 radiusMax=self.dim1Upper)
        tracked, newRois = self.tracker.track(rois)
        self.numObjects = self.tracker.N

        if self.guiMode:
            for roi in rois:

                ImgUtils.drawRect(roi, img)
                detectedCentroid = ImgUtils.findRoiCentroid(roi)
                ImgUtils.drawCircle(detectedCentroid, img, colour=(255, 0, 0))
                ImgUtils.putText(coords=(roi[0] + 50, roi[1] + 50),
                                 text=str(roi[2] - roi[0]),
                                 img=img,
                                 colour=(255, 255, 0),
                                 fontSize=3)
            for objectId, centroid in tracked.items():
                ImgUtils.drawCircle((centroid[0], centroid[1]), img)
                ImgUtils.putText(coords=centroid,
                                 text=str(objectId % 1000),
                                 img=img,
                                 colour=(255, 0, 0))

        out = []

        for roi in newRois:
            colour = self.colour(origImg[roi[1]:roi[3], roi[0]:roi[2]])
            self.averageColour[0] += colour[0]
            self.averageColour[1] += colour[1]
            self.averageColour[2] += colour[2]
            self.averageSize += roi[3] - roi[1]

        return img, contrast, out