[OpenR8 solution] Image_FindRotateVerticalAngle (Find the tilt angle of the image object)
  1. Chapter1: Image_FindRotateVerticalAngle Introduction

 

Image_FindRotateVerticalAngle is a solution for processing images to find the tilt angle and then rotate the image according to the angle, as shown in Fig. 1.

 

Fig. 2 shows the flow of the solution of ImageFindRotateVerticalAngle. The usage and process descriptions are described in Chapters 3 and Chapter 4.

 

※ According to the different pictures, the way to process the pictures is different. For the processing of the pictures in this file, please refer to Chapter 5.

 

Fig. 1. The goal of the solution.png

Fig. 1. The goal of the solution.

 

Fig. 2. Flow chart of the solution.png

Fig. 2. Flow chart of the solution.

 

 

  1. Chapter2: Image_FindRotateVerticalAngle Folder Introduction

 

Image_FindRotateVerticalAngle is in the solution folder of OpenR8, as shown in Fig. 3, which has a flow file and an image file, as shown in Fig. 4.

  1. ImageFindRotateVerticalAngle.flow: Find the solution for angles and rotate the image.
  2. sample.png: The image used by the solution.

 

Fig. 3. Image_FindRotateVerticalAngle location.png

Fig. 3. Image_FindRotateVerticalAngle location.

 

Fig. 4. Image_FindRotateVerticalAngle folder.png

Fig. 4. Image_FindRotateVerticalAngle folder.

 

 

  1. Chapter3: Open and run ImageFindRotateVerticalAngle.flow

 

Please click "File" => "Open" => "to enter the solution folder under OpenR8" => "Select Image_FindRotateVerticalAngle folder" => "Select ImageFindRotateVerticalAngle.flow ", such as Fig. 5, Fig. 6.

 

Fig. 5. Select ImageFindRotateVerticalAngle.flow.png

Fig. 5. Select ImageFindRotateVerticalAngle.flow.

 

Fig. 6. Open ImageFindRotateVerticalAngle.flow.png

Fig. 6. Open ImageFindRotateVerticalAngle.flow.

 

After turning it on, select Image_Open to select the image you want to rotate.

 

※ If you just want to see the default execution results, you don't have to choose.

 

Fig. 7. Select the image that want to rotate.png

Fig. 7. Select the image that want to rotate.

 

After selecting the image, you can press to run.

 

Fig. 8. Run ImageFindRotateVerticalAngle.flow.png

Fig. 8. Run ImageFindRotateVerticalAngle.flow.

 

Fig. 9. The results are roughly explained.png

Fig. 9. The results are roughly explained.

 

※If the angle of the result after the correction is not satisfactory, please adjust the way the image is processed.

 

 

  1. Chapter4: ImageFindRotateVerticalAngle.flow process

 

This section focuses on the functionality of the ImageFindRotateVerticalAngle.flow process.

 

※There are special instructions for dealing with images. See Chapter 5 for details.

 

Fig. 10. ImageFindRotateVerticalAngle.flow process.png

Fig. 10. ImageFindRotateVerticalAngle.flow process.

 

  1. Image_Open:

Open the image you want to rotate.

imageFileName: Select an image by button.

image: Output the image read in.

 

Fig. 11. ImageFindRotateVerticalAngle.flow - Image_Open.png

Fig. 11. ImageFindRotateVerticalAngle.flow - Image_Open.

 

  1. Image_Show:

Display the image you want to rotate (the original image of Fig. 9).

image: Select the image output by Image_Open.

displayPercenrage: The displayed image zoom rate is preset to 100 (=100% normal size) when not filled.

windowTitle: The name of the window displayed.

 

Fig. 12. ImageFindRotateVerticalAngle.flow - Image_Show.png

Fig. 12. ImageFindRotateVerticalAngle.flow - Image_Show.

 

※The practice of the third point to the sixth point is explained in Chapter 5.

 

  1. Image_Split:

Divide the color image into three channels: blue, green, and red.

image: Select the image output by “Image_Open”.

image B: Output an image of the blue channel.

image G: Output an image of the green channel.

image R: Output an image of the red channel.

※“Image_Open” selected image will not be split if it is a grayscale image (single channel)!

 

Fig. 13. ImageFindRotateVerticalAngle.flow - Image_split.png

Fig. 13. ImageFindRotateVerticalAngle.flow - Image_split.

 

  1. Image_Diff:

The two images are subtracted. This is used for “Image_Split” G channel - “Image_Split” B channel.

imaegA: minuend.

imageB: subtrahend.

ImageDiff: Output an image of Image (Image A - Image B).

mode: There are two modes, mode 0 and mode 1, where mode 0 is selected.

※Image_Diff mode 0 Formula: ImageDiff = Image A - Image B

※Image_Diff mode 1 Formula: ImageDiff = Image A - Image B + 128

 

Fig. 14. ImageFindRotateVerticalAngle.flow - Image_Diff.png

Fig. 14. ImageFindRotateVerticalAngle.flow - Image_Diff.

 

  1. Image_Show:

The “Image_Diff” image output is displayed (Fig. 9 image1).

image: Select the image output by“Image_Diff”.

displayPercentage: The displayed image zoom rate is preset to 100 (=100% normal size) when not filled.

windowTitle: The name of the window displayed.

 

Fig. 15. ImageFindRotateVerticalAngle.flow - Image_Show.png

Fig. 15. ImageFindRotateVerticalAngle.flow - Image_Show.

 

  1. Image_Binarize:

Binarize the image subtracted from “Image_Diff” and filter out the green square in the middle.

image: Select the image output by “Image_Diff”.

threshold: The threshold for binarization.

imageBinarize: The binarized image is output.

 

Fig. 16. ImageFindRotateVerticalAngle.flow - Image_Binarize.png

Fig. 16. ImageFindRotateVerticalAngle.flow - Image_Binarize.

 

  1. Image_Show:

The “Image_Binarize” image output is displayed (Fig. 9 image2).

image: Select the image output by “Image_Binarize”.

displayPercentage: The displayed image zoom rate is preset to 100 (=100% normal size) when not filled.

windowTitle: The name of the window displayed.

 

Fig. 17. ImageFindRotateVerticalAngle.flow - Image_Show.png

Fig. 17. ImageFindRotateVerticalAngle.flow - Image_Show.

 

  1. Image_FindRotateVerticalAngle:

Calculate the tilt angle of the image feature.

image: Select the image output by “Image_Binarize.

maxFixAngle: The maximum angle at which the image can rotate. If the angle found is greater than the value of this parameter, the output angle is 0, as shown in Fig. 19.

outputAngle: The rotation angle of the output image feature.

 

Fig. 18. ImageFindRotateVerticalAngle.flow - Image_FindRotateVerticalAngle.png

Fig. 18. ImageFindRotateVerticalAngle.flow - Image_FindRotateVerticalAngle.

 

Fig. 19. The relationship between the maximum correction angle and the output angle of Image_FindRotateVerticalAngle.png

Fig. 19. The relationship between the maximum correction angle and the output angle of Image_FindRotateVerticalAngle.

 

  1. Image_Rotate:

Rotate the original image read by “Image_Open” according to the angle output by “Image_FindRotateVerticalAngle”.

image: Select the image output by “Image_Open”.

degree: Select the angle that “Image_FindRotateVerticalAngle” is output.

imageRotate: Output the rotated image.

 

Fig. 20. ImageFindRotateVerticalAngle.flow - Image_Rotate.png

Fig. 20. ImageFindRotateVerticalAngle.flow - Image_Rotate.

 

Fig. 21. rotate image.png

Fig. 21. rotate image.

 

  1. Image_Crop:

According to “Image_Rotate”, there will be black blocks in the image, so the black block should be cut off, as shown in Fig. 23.

image: The image output by “Image_Rotate”, as shown in Fig. 24.

x: The starting point of the crop is the X coordinate, as shown in Fig. 24.

y: The starting point of the crop is the Y coordinate, as shown in Fig. 24.

w: The width of the crop (from the starting point of the crop), as shown in Fig. 24.

h: The height of the crop (from the starting point of the crop), as shown in Fig. 24. imageCrop: Output the cropped image as shown in Fig. 24.

 

Fig. 22. ImageFindRotateVerticalAngle.flow - Image_Crop.png

Fig. 22. ImageFindRotateVerticalAngle.flow - Image_Crop.

 

Fig. 23. Black area caused by Image_Rotate reason for cropping .png

Fig. 23. Black area caused by Image_Rotate reason for cropping.

 

Fig. 24. Image_Crop.png

Fig. 24. Image_Crop.

 

  1. Image_Show:

The “Image_Crop” image output is displayed (Fig. 9 image3).

image: Select the image output by Image_Crop.

displayPercenrage: The displayed image zoom rate is preset to 100 (=100% normal size) when not filled.

windowTitle: The name of the window displayed.

 

Fig. 25. ImageFindRotateVerticalAngle.flow - Image_Show.png

Fig. 25. ImageFindRotateVerticalAngle.flow - Image_Show.

 

  1. WaitKey:

After Image_Show, you must add WaitKey to see the image, and how many microseconds the image stays.

keyCode: The output signal.

milliSencond: If you want the image to be turned off until any key is pressed, set 0. If you want the image to be displayed after 1 second, set 1000.

※1 Second = 1000 microsecond.

 

Fig. 26. ImageFindRotateVerticalAngle.flow - WaitKey.png

Fig. 26. ImageFindRotateVerticalAngle.flow - WaitKey.

 

  1. Image_DestoryAllWindows:

Close all image windows displayed by Image_Show.

 

 

  1. Chapter5: Image processing

 

Before you input the processed image into “Image_FindRotateVerticalAngle”, you need to do some processing to leave useful information and exclude unnecessary data. Common methods are like binarization, blur, erode, dalite, add, subtract, etc.The following describes the solution of ImageFindRotateVerticalAngle.flow.

 

※The method is for reference only and it is not necessary to use these practices.

 

Since the picture of Fig. 27is greenish, there is some noise in the direct use of binarization to filter out the green frame completely, so the solution of ImageFindRotateVerticalAngle.flow uses Image_split to separate blue, green and red channel, as shown in Fig. 28.

 

Fig. 27. Image used by ImageFindRotateVerticalAngle.flow.png

Fig. 27. Image used by ImageFindRotateVerticalAngle.flow.

 

Fig. 28. Image_Split of three channel.png

Fig. 28. Image_Split of three channel.

 

It can be seen that the blue channel and the green channel of Fig. 28clearly see the shape of the rectangle, and one is black and one is white, so use “Image_Diff”, use green channel – blue channel, try to filter the rectangle area, as shown in Fig. 29.

 

Fig. 29. Image_Diff result.png

Fig. 29. Image_Diff result.

 

“Image_Diff” after subtracting the result, it is obvious that there is a rectangle in the center, and other areas are black. In this case, use “Image_Binarize” to filter out the rectangle, as shown in Fig. 30.

 

Fig. 30. Image_binarize result.png

Fig. 30. Image_binarize result.

 

 


Recommended Article

1.
OpenR8 Community Edition - AI Software for Everyone (Free Download)