Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can do this job by using FindContours

  1. If Image is color convert Gray by using cvtColor.
  2. Convert the image to black and white , by using cv2.threshold, cv2.adaptiveThreshold.
  3. Be sure that the forground digist are white and the background is black
  4. Use findcontours to find all regions in the image
  5. Sort All regions from left to right.
  6. Loop on all regions and find the avarage width and avarage hight , you can ignore very small and very big regions.
  7. Loop again and Strart to collect the regions into line ,
  8. take region if it it's larger than Threshold1 a and less than Threshold2 add the region to line , Threshold1 and Threshold2 can be calculated from Avarage say Threshold1 > 0.7 Avarage and Threshold2 < 1.3 Avarage
  9. If the image contain more than one line , you can add new line when the traget region doe not intersect with any previouse lines , it the target region intersect with line just add the region to the line and update the line rectangle by merging the line and traget region
  10. Now you have all lines in the image and all regions inside every line

You can do this job by using FindContours

  1. If Image is color convert Gray by using cvtColor.
  2. Convert the image to black and white , by using cv2.threshold, cv2.adaptiveThreshold.
  3. Be sure that the forground digist are white and the background is black
  4. Use findcontours to find all regions in the image
  5. Sort All regions from left to right.
  6. Loop on all regions and find the avarage width and avarage hight , you can ignore very small and very big regions.
  7. Loop again and Strart to collect the regions into line ,
  8. take region if it it's larger than Threshold1 a and less than Threshold2 add the region to line , Threshold1 and Threshold2 can be calculated from Avarage say Threshold1 > 0.7 Avarage and Threshold2 < 1.3 Avarage
  9. If the image contain more than one line , you can add new line when the traget region doe not intersect with any previouse lines , it if the target region intersect with line just add the region to the line and update the line rectangle by merging the line and traget regionregion.
  10. Now you have all lines in the image and all regions inside every line