Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
847 B

  1. import cv2
  2. image = cv2.imread("logo.jpg", 1)
  3. img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  4. cv2.threshold(img, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU, img)
  5. cv2.bitwise_not(img, img)
  6. rect_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (30, 5))
  7. img = cv2.morphologyEx(img, cv2.MORPH_CLOSE, rect_kernel)
  8. contours, hier = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  9. if len(contours) != 0:
  10. ROI_number = 0
  11. for c in contours:
  12. x,y,w,h = cv2.boundingRect(c)
  13. # Depends on text size, so the greater the value the less objects we get.
  14. if (h > 50):
  15. cv2.rectangle(image, (x,y), (x+w,y+h), (0,0,255), 1)
  16. ROI = image[y:y+h, x:x+w]
  17. cv2.imwrite('results/ROI_{}.png'.format(ROI_number), ROI)
  18. ROI_number += 1
  19. cv2.imshow("Result", image)
  20. cv2.waitKey(0)