ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Convert Image To Document Like CamScan
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

mazluta

Israel
12 Posts

Posted - May 19 2025 :  07:07:23  Show Profile  Reply
i have Delphi UniGui DMS Application (Document Management System).
first part is browser desktop and the second is web mobile application.
in the web mobile app i give the user the option to take "picture" using camera device.
so - let say i have 5 images ("pictures" by mobile camera device).
now - i want to convert them to 1 pdf file as DOCUMENT.
to create pdf from those 5 images there is no problem.
what i want is convert the images to document page "like" it scanned using scanner.
like CamScan Dose.

can i do it with the ImageEn Components or Envision?

Yossi Mazal-Tov

xequte

39020 Posts

Posted - May 19 2025 :  15:59:31  Show Profile  Reply
Hi Yossi

So you mean convert them to a document that is searchable and selectable?

You can do it with TIEVisionSearchablePDFGenerator:

http://www.imageen.com/help/TIEVisionSearchablePDFGenerator.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

mazluta

Israel
12 Posts

Posted - May 19 2025 :  16:27:39  Show Profile  Reply
first thanks.
no, i mean to :
"Straighten" the image
and turn it into an A4 page "Document".
from then i will join al the images in the package and make them "one" pdf document.
there is application in mobile -CamScanner - they do it. as it should.


Yossi Mazal-Tov
Go to Top of Page

mazluta

Israel
12 Posts

Posted - May 19 2025 :  16:45:56  Show Profile  Reply
i asked "Gemini" (he is my closest friend now).

You're looking to implement document straightening and conversion to a standard A4 document size from images captured with a mobile UniGUI application, similar to CamScanner. You then want to combine these processed images into a single PDF.

Here's a breakdown of how you might approach this using Delphi components, primarily focusing on ImageEn (as it's a powerful imaging library):

1. Capturing Images (Your Current Code)

Your existing UniGUI mobile application already handles capturing images from the camera and displaying them. You're saving these as PNG or JPG files in the server's local cache. This part seems to be working correctly.

2. Image Straightening (Perspective Correction)

This is the core of the "CamScanner" effect. You need to perform a perspective transformation to correct for the camera's angle when the photo was taken.

Detecting Document Edges: The first step is to identify the four corners of the document in the image. This can be done using various image processing techniques:
Edge Detection: Algorithms like Canny edge detection can highlight the edges in the image.
Hough Transform: Can be used to detect lines, which might form the document's boundaries.
Blob Analysis: Identifying rectangular or near-rectangular shapes.
Finding the Corners: Once edges or shapes are detected, you'll need to find the four corner points that define the document. This might involve analyzing intersections of lines or the vertices of detected shapes.
Perspective Transformation: Once you have the four corner points of the document in the original image, and you know the desired output dimensions (A4 ratio), you can calculate a perspective transformation matrix. This matrix can then be used to warp the original image so that the detected document becomes a rectangular A4-sized image.
Using ImageEn for Straightening:

ImageEn has powerful functions that can help with this:

EIJEdgeDetect: For edge detection.
EIHHoughLines: For detecting lines.
IEPerspective: Performs perspective transformations. You would need to provide the source corner points and the destination corner points (forming an A4 ratio rectangle).
You would likely need to implement a process like this:

Load the captured image into an TIEBitmap.
Use edge detection and possibly line detection to find the boundaries of the document.
Implement logic to identify the four corner points of the document from the detected features. This might be the most complex part and could involve some custom algorithms.
Define the target A4 rectangle's corners.
Use IEPerspective with the source and target corners to straighten the image.
3. Converting to A4 "Document" Size

After straightening, you'll want to ensure the image has the aspect ratio of an A4 page. You might need to:

Scale: Resize the straightened image to have the approximate proportions of A4.
Add White Borders: If the straightened document doesn't perfectly fit the A4 ratio, you could add white borders to make it conform.
ImageEn's resizing capabilities (IEScale, IEResize) would be useful here.

4. Combining Images into a Single PDF

Once you have processed each captured image into a straightened, A4-like "document" image, you can combine them into a single PDF file.

Using ImageEn for PDF Creation:

ImageEn provides classes for PDF creation:

TIEPDFDocument: Allows you to create and manipulate PDF documents.
You can add each processed TIEBitmap as a new page to the PDF document using methods of TIEPDFDocument.
Example Workflow:

User captures one or more images using your UniGUI mobile app.
The images are saved on the server.
For each image: a. Load the image into a TIEBitmap. b. Implement your document edge detection and corner finding logic. c. Define the target A4 rectangle corners. d. Use IEPerspective to straighten the image. e. Resize or add borders to make it A4 ratio.
Create a TIEPDFDocument.
Add each processed TIEBitmap as a new page to the TIEPDFDocument.
Save the TIEPDFDocument to a file, which can then be downloaded by the user.
Other Components:

While ImageEn is a strong contender, other Delphi imaging libraries like Graphics32 or custom image processing routines could also be used, but ImageEn likely offers the most convenient set of tools for this task.

Challenges:

Robust Corner Detection: Accurately and reliably detecting the corners of the document in various lighting conditions and with different backgrounds can be challenging. This might require experimentation with different image processing techniques and parameter tuning.
Performance: Image processing can be CPU-intensive. For mobile applications, you'll need to consider the performance on the server if you're doing the processing there.
To help you further, could you clarify:

Do you already have ImageEn or Envision components in your project?
Are you looking for specific code examples for certain steps (like perspective transform with ImageEn)?

Let me know how you'd like to proceed!

some times he lie so we start with the flow and see what will be - Ca Sera Sera

if you have something. please advise.

Yossi Mazal-Tov
Go to Top of Page

xequte

39020 Posts

Posted - May 19 2025 :  17:19:17  Show Profile  Reply
Sorry, I'm not really understanding your requirement. Please attach some examples.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

mazluta

Israel
12 Posts

Posted - May 19 2025 :  18:32:15  Show Profile  Reply








the user take a picture of page 1
and then page 2

i want to take those "images" (page 1 + page 2), "align" them, turn them into A4 pages, and then create a PDF file from them that will contain 2 pages.


Yossi Mazal-Tov
Go to Top of Page

mazluta

Israel
12 Posts

Posted - May 19 2025 :  18:35:32  Show Profile  Reply
the end will be (if it possible) like that

attach/mazluta/2025519183522_ComSigm-CTD.pdf

Yossi Mazal-Tov
Go to Top of Page

xequte

39020 Posts

Posted - May 20 2025 :  01:06:14  Show Profile  Reply
Hi Yossi

Creating a PDF with two pages from two images is fairly simple.

You can do it by adding the images to a TImageEnMView and then saving as PDF:

http://www.imageen.com/help/TImageEnMIO.SaveToFilePDF.html

Or using the PDF Builder:

http://www.imageen.com/help/TIEPDFBuilder.html

Or as mentioned earlier:

http://www.imageen.com/help/TIEVisionSearchablePDFGenerator.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

mazluta

Israel
12 Posts

Posted - May 20 2025 :  05:05:58  Show Profile  Reply
no problem to create the pdf.
the problem is the "To straighten" the image that was taken from the "camera" so it will like "document" and not like "picture"

is this the way to "stainghten" the "image" :

ImageEn has powerful functions that can help with this:

EIJEdgeDetect: For edge detection.
EIHHoughLines: For detecting lines.
IEPerspective: Performs perspective transformations. You would need to provide the source corner points and the destination corner points (forming an A4 ratio rectangle).
You would likely need to implement a process like this:

Load the captured image into an TIEBitmap.
Use edge detection and possibly line detection to find the boundaries of the document.
Implement logic to identify the four corner points of the document from the detected features. This might be the most complex part and could involve some custom algorithms.
Define the target A4 rectangle's corners.
Use IEPerspective with the source and target corners to straighten the image.
3. Converting to A4 "Document" Size

After straightening, you'll want to ensure the image has the aspect ratio of an A4 page

Yossi Mazal-Tov
Go to Top of Page

xequte

39020 Posts

Posted - May 20 2025 :  17:06:08  Show Profile  Reply
Sorry Yossi, I see what you mean. You can perform automatic deskewing using methods like:

http://www.imageen.com/help/TImageEnProc.SkewDetection.html

But I wouldn't expect it to work well on images like that.

There are no other built-in functions for this.

If you want to test using hough lines:

http://www.imageen.com/help/TIEVisionImage.houghLines.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

mazluta

Israel
12 Posts

Posted - May 21 2025 :  07:52:37  Show Profile  Reply
thanks

Yossi Mazal-Tov
Go to Top of Page

mazluta

Israel
12 Posts

Posted - May 21 2025 :  16:31:50  Show Profile  Reply
ok. when i load the image 2 with
ImageEnView1.IO.LoadFromFileJpeg('c:\Work\MzFixImage\image\page 2.jpeg')
and manipulate it with :
ImageEnView1.Proc.EdgeDetect_Sobel;

and save the result with :
ImageEnView1.IO.SaveToFileJpeg('c:\Work\MzFixImage\image\page 2 new.jpeg')

i get the image :




how do i get the corners ?

Yossi Mazal-Tov
Go to Top of Page

xequte

39020 Posts

Posted - May 21 2025 :  19:13:13  Show Profile  Reply
Hi Yossi

Yes, there's not a built-in method for that. You could try using hough lines. Parse all the lines returned to get the MinX, MinY, MaxX and MaxY and assume those are the four corners, but I'm not sure how well it would work:

http://www.imageen.com/help/TIEVisionImage.houghLines.html

Use a quadrilateral crop to "square" the result:

http://www.imageen.com/help/TImageEnProc.Crop.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

39020 Posts

Posted - May 21 2025 :  19:26:34  Show Profile  Reply
Another option might be to use findContours to find all page objects and then calculate your min, max points:

http://www.imageen.com/help/TIEVisionImage.findContours.html

You might need to clean up the image using thresholding:

http://www.imageen.com/help/TIEVisionImage.threshold.html

And/or removing noise, e.g.:

http://www.imageen.com/help/TImageEnProc.RemoveNoise.html

or Canny edge detection:

http://www.imageen.com/help/TIEVisionImage.canny.html


Unfortunately, I'm away till the end of May, so cannot test this for you.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

mazluta

Israel
12 Posts

Posted - May 22 2025 :  03:45:56  Show Profile  Reply
thanks Nigel.
i hope you have good vacation.

Yossi Mazal-Tov
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: