#In the case of processing images from a directory, I first gather all the image names into a list. Then, for each item in the list, I call the renaming function, retrieving both the name and the image. However, for the case of a single image, I needed to adapt the process. In this mode, the image name and the image itself are initialized at the beginning of the class. To keep the process consistent, I created a list with a single element, allowing the flow to continue. The value in the list, whether '1' or otherwise, isn't significant—what's important is that both the directory processing and single-image modes rely on a list of images, with the key difference being the initialization process I mentioned.
self.logger.info("Enhancing took %.1fs ",time.time()-t0)
self.logger.info("Enhancing took %.1fs ",time.time()-t0)
t1=time.time()
t1=time.time()
#In the lightweight version, I aimed to extract the layout and text lines using artificial classes and ground-truth (GT) images at smaller scales, making the process faster. In this mode, both layout and textline detection are handled by a function called get_regions_light_v
self.logger.info("Graphics detection took %.1fs ",time.time()-t1)
self.logger.info("Graphics detection took %.1fs ",time.time()-t1)
#self.logger.info('cont_page %s', cont_page)
#self.logger.info('cont_page %s', cont_page)
#Our column classification model is trained to handle documents with 1 to 6 columns, but it does not account for empty pages. However, using a heuristic based on the layout results, it is possible to determine if a page is empty. For an empty page, the number of columns is set to None, making it unnecessary to continue with further processing. In such cases, I simply write the print space coordinates into the PageXML and finish the process for single-image mode, while continuing the flow for directory-based processing.
ifnotnum_col:
ifnotnum_col:
self.logger.info("No columns detected, outputting an empty PAGE-XML")
self.logger.info("No columns detected, outputting an empty PAGE-XML")
self.logger.info("detection of marginals took %.1fs",time.time()-t1)
self.logger.info("detection of marginals took %.1fs",time.time()-t1)
t1=time.time()
t1=time.time()
#As we have both a full layout mode and a mode without full layout detection, in the case of full layout mode, we need to perform complete layout detection and add the information to the initial layout results.
#The heuristic reading order works well when the document is not skewed. However, a skewed document can degrade the results. To prevent this degradation, in the case of significant skew, we first deskew the layout and determine the reading order, then adjust that reading order to match the original skewed layout. Here, I check whether the skew angle exceeds a certain threshold before applying this process.