Exemplo n.º 1
0
    def crop_cell_hull(self, image, i, text, xscale=1., yscale=1.):
        """
        Crop a single cell hull as a filled polygon
        """
        # Drawing functions need pure integer coordinates
        thehull = np.rint(
            cv_algorithms.scaleByRefpoint(self.cell_hulls[i], xscale,
                                          yscale)).astype(np.int)
        # Draw the polygon
        #cv2.fillConvexPoly(img, thehull, color=fill_color)

        #print('Hull {0}'.format(text))
        #print(self.cell_hulls[i])
        print(thehull)

        #x,y,h,w = self.getOriginAndHeightAndWidth(thehull)
        #crop = img[y:y+h, x:x+w]
        #print('------------')

        if text is not None:
            x, y, h, w = self.getOriginAndHeightAndWidth(thehull)
            crop = image[y - 30:y + h, x - 30:x + w]
            cv2.imwrite("" + text + ".png", crop)
            #txt = self.stage1Tesseract(Image.open('/home/vijay/workspace/OpevCV/'+text+'.png'))
            txt = self.stage1Tesseract(
                cv2.imread('/home/vijay/workspace/OpevCV/' + text + '.png'))
            print('{0}: {1}'.format(text, txt))
Exemplo n.º 2
0
 def draw_cell_hull(self,
                    img,
                    i,
                    text,
                    xscale=1.,
                    yscale=1.,
                    textsize=1,
                    fill_color=(255, 255, 0)):
     """
     Draw a single cell hull as a filled polygon
     """
     # Drawing functions need pure integer coordinates
     thehull = np.rint(
         cv_algorithms.scaleByRefpoint(self.cell_hulls[i], xscale,
                                       yscale)).astype(np.int)
     # Draw the polygon
     cv2.fillConvexPoly(img, thehull, color=fill_color)
     # Draw text
     if text is not None:
         thehull_center = np.mean(thehull, axis=0)
         boxWidth, boxHeight = np.ptp(thehull,
                                      axis=0)  # Max X/Y extent of the box
         cv_algorithms.putTextAutoscale(img,
                                        text,
                                        thehull_center,
                                        cv2.FONT_HERSHEY_SIMPLEX,
                                        boxWidth,
                                        boxHeight,
                                        color=(0, 0, 0),
                                        thickness=2)
Exemplo n.º 3
0
    def draw_cell_hull(self,
                       img,
                       i,
                       text,
                       xscale=1.,
                       yscale=1.,
                       textsize=1,
                       fill_color=(255, 255, 0)):
        """
        Draw a single cell hull as a filled polygon
        """
        # Drawing functions need pure integer coordinates
        thehull = np.rint(
            cv_algorithms.scaleByRefpoint(self.cell_hulls[i], xscale,
                                          yscale)).astype(np.int)
        # Draw the polygon
        # cv2.fillConvexPoly(img, thehull, color=fill_color)

        #print('Hull {0}'.format(text))
        #print(self.cell_hulls[i])
        #print(thehull)

        #x,y,h,w = self.getOriginAndHeightAndWidth(thehull)
        #crop = img[y:y+h, x:x+w]
        #print('------------')

        #crop = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        #crop = img[thehull[0][0]:thehull[1][1], thehull[2][0]:thehull[3][1]]
        #if text is not None:
        #cv2.imwrite(""+text+".png", crop)
        # Draw text
        if text is not None:
            cv2.fillConvexPoly(img, thehull, color=fill_color)

            #x,y,h,w = self.getOriginAndHeightAndWidth(thehull)
            #boxWidth, boxHeight = np.ptp(thehull, axis=0)
            #w = boxWidth
            #h = boxHeight
            #crop = img[y:y+h, x:x+w]
            #cv2.imwrite(""+text+".png", crop)
            #txt = pytesseract.image_to_string(Image.open('/home/vijay/workspace/OpevCV/'+text+'.png'))
            #txt = txt.replace('\r', '').replace('\n', '')
            #print('Text: '+txt)

            thehull_center = np.mean(thehull, axis=0)
            boxWidth, boxHeight = np.ptp(thehull,
                                         axis=0)  # Max X/Y extent of the box
            cv_algorithms.putTextAutoscale(img,
                                           text,
                                           thehull_center,
                                           cv2.FONT_HERSHEY_SIMPLEX,
                                           boxWidth,
                                           boxHeight,
                                           color=(0, 0, 0),
                                           thickness=2)
Exemplo n.º 4
0
 def draw_cell_hull(self, img, i, text, xscale=1., yscale=1., textsize=1, fill_color=(255,255,0)):
     """
     Draw a single cell hull as a filled polygon
     """
     # Drawing functions need pure integer coordinates
     thehull = np.rint(cv_algorithms.scaleByRefpoint(self.cell_hulls[i], xscale, yscale)).astype(np.int)
     # Draw the polygon
     cv2.fillConvexPoly(img, thehull, color=fill_color)
     # Draw text
     if text is not None:
         thehull_center = np.mean(thehull, axis=0)
         boxWidth, boxHeight = np.ptp(thehull, axis=0) # Max X/Y extent of the box
         cv_algorithms.putTextAutoscale(img, text, thehull_center, cv2.FONT_HERSHEY_SIMPLEX,
                                        boxWidth, boxHeight, color=(0,0,0), thickness=2)