[OpenR8 solution] Image_Cap (Detect if the cap is tight)
  1. Image_Cap

 

The Image_Cap is to detect whether the cap is covered and tight. Fig. 1 below.

 

Fig. 1. Find a schematic that the cap is not covered..png

Fig. 1. Find a schematic that the cap is not covered.

 

 

  1. Introduction to use

 

This section describes how users can load an existing solution through the R8 software to detect whether the cap is tight.

 

Step 1. Run R8.exe. Please click on the mouse twice to open the R8. The picture is shown in Figure 2 below.

 

Fig. 2. Run R8.exe ..jpg

Fig. 2. 【Run R8.exe】.

 

Step 2. Click "File" => "open" above R8. The picture is shown in Fig. 3 below.

 

Fig. 3. File Open ..png

Fig. 3. 【File】=>【Open】.

 

Step 3. Select the Image_cap folder under solution. Figure 4 below.

 

Fig. 4. Solution Folder..jpg

Fig. 4. Solution Folder.

 

Step 4. Select and open flow files. Fig. 5, Fig. 6 below.

 

Fig. 5. Select a flow file..jpg

Fig. 5. Select a flow file.

 

Fig. 6. Open flow File..jpg

Fig. 6. Open flow File.

 

Step 5. Select a diagram that you want to determine if the cap is tight. Fig. 7 below.

 

Fig. 7. Select the barcode diagram you want to parse..png

Fig. 7. Select the barcode diagram you want to parse.

 

Step 6. Run and Display results. Fig. 8 below.

If you want to adjust the parameters in the process, you can see that the next chapter details the process content. By adjusting the parameters to adapt to a variety of situations, so that the effect is better.

 

 

  1. Introduction to process Content

 

The process of this solution. Fig. 9 below.

 

Fig. 9. Processes within the solution..jpg

Fig. 9. Processes within the solution.

 

Fig. 10. The image you want to detect..png

Fig. 10. The image you want to detect.

 

See Fig. 10 above the left cap is not covered tight, the right cap is covered. 

 

  1. First, the cap is the area we're interested in, so we need to find a way to filter the cap out of the background. In this article, we use image processing such as binary to filter out the cap.
  2. Then, how do you know it's not tight? As can be seen from the picture, the CAP usually consists of two pieces, and when not covered, the one above will be larger than the distance below. Conversely, the distance is small.

By capping this property, we can tell that if the upper and lower areas are joined together, it is tight.

  1. Finally, from the 1th to obtain the current bottle cap situation image. From the 2nd you can get a tightly covered image.

Bottle cap gap = a tightly covered image – Current status image This allows you to set the gap more than how much is not covered, that is, the uncovered cap is detected.

 

The process is from up to bottom:

 

【Open and display input images】 Select the diagram that you want to detect if the cap is tight and display it in the window. Fig. 11 below. function contains

1 Image_Open

2 Image_Show

 

Fig. 11. Display the Read image..jpg

Fig. 11. Display the Read image.

 

function

Variable name

name

value

Usage

Image_Open

imageFileName

Cap.png

Cap.png

An image that wants to detect whether the cap is tight.

Image (image)

Sample

 

Saves the read-in image to this variable.

Image_Show

Image

Sample

 

Select the image variable you want to display.

displayPercentage (int)

 

 

Displays the percentage of the graph. A value of 200 means 200 (the picture is magnified one times), 50 means 50 (the picture is halved), and so on, zoom in and out.

windowTitle (String)

windowTitle1

Sample

The title of the window that displays the image. The window name is Sample. As shown in Figure 11 above, the title of the window.

 
 

【Initial filtration of the cap】Image to the gray-scale, and then binarize gray-scale image, the bottle cap initially filtered out from the background. Fig. 12 below.

 

3 Image_Gray

4 Image_Show

5 Image_Binarize

6 Image_Show

 

Fig. 12. Left is grayscale image right is binary image..png

Fig. 12. Left is grayscale image right is binary image.

 

function

Variable name

name

value

Usage

Image_Gray

imageColor

Sample

 

Color image images that you want to turn the grayscale.

imageGray

Image_Gray

 

The image that will be converted to the grayscale is saved to this variable.

Image_Show

Image

Image_Gray

 

Select the image variable you want to display.

displayPercentage

 

 

Displays the percentage of the graph. A value of 200 means 200 (the picture is magnified one times), 50 means 50 (the picture is halved), and so on, zoom in and out.

windowTitle

windowTitle1

Image_Gray

The title of the window that displays the image. The window name is sampleimage.

Image_Binarize

Image

Image_Gray

 

The source image of the binarization.

Threshold

ThresholdValue

210

The threshold value of binarization.

imageBinarize

Image_Binarize

 

Finish the binary image to store this variable.

Image_Show

image

Image_Binarize

 

Select the image variable you want to display.

displayPercentage

 

 

Displays the percentage of the graph. A value of 200 means 200 (the picture is magnified one times), 50 means 50 (the picture is halved), and so on, zoom in and out.

windowTitle

windowTitle2

Image_Binarize

The title of the window that displays the image. The window name is image_binarize.

 

 

【Further filter the cap to make it cleaner】You can learn from the previous filter diagram (Fig. 13 below), in addition to the bottle cap, there are filters out some of the bottle body is we do not want the area. So then we filter out the non-cap with some image processing.

 

  1. From Fig. 13 to the right, you can see that the area of the cap is significantly larger than in other areas, and you want to filter out the upper and lower areas of the cap, so we can do the blur first. As shown in Fig. 13 below. Then, because the cap area is significantly more concentrated, so the blur is also brighter than other areas, through the image binarization, the brighter area is filtered out, as shown below in the right Fig. 13.

 

Fig. 13. Left is the binary result of the previous step. The middle is a blur result. Right is binary result..png

Fig. 13. Left is the binary result of the previous step. The middle is a blur result. Right is binary result.

 

  1. From above, the area of the cap is obtained, and it is possible to know which areas of the binary image is bottle caps. This can be achieved by [image _ and] by using an image of the two-valued image and the cap area. Fig. 14 below gets right in the left and middle.

 

Note: Image _ and: In the same position, both images are white, then this position is white. Conversely, as long as one of them is black, the position is black.

 

Fig. 14. The left image is a binary image. The middle image is the area of the cap. The right image is the filtered cap..png

Fig. 14. The left image is a binary image. The middle image is the area of the cap. The right image is the filtered cap.

 

7  Image_Blur : Find the area where the bottle cap is located.

8  Image_Binarize : Once again, the object is filtered out from the background.

9  Image_Show

10 Image_And

11 Image_Show

 

 

function

Variable name

name

value

use

Image_Blur

image

Image_Binarize

 

A source image for blur processing.

sizeX

SizeX

100

In the left and right direction how much distance to do blur. The larger the value, the wider the blur distance.

sizeY

SizeY

55

How much distance to make blur in the upper and lower directions.

imageBlur

Image_1

 

The image is saved to this variable after the blur is done.

Image_Binarize

Refer to Image_Binarize file

image

Image_1

 

The source image that you want to make a binarization.

Threshold

ThresholdValue_1

128

The threshold value of binarization.

imageBinarize

Image_1

 

Save the binary image to this variable.

Image_Show

Image

Image_1

 

Select the image variable you want to display.

displayPercentage

 

 

Displays the percentage of the image. A value of 200 means 200 (the image size is magnified one times), 50 means 50 (the image size is halved), and so on, zoom in and out.

windowTitle

windowTitle3

Image_1

The title of the window that displays the image. The window name is image_1.

Image_And

imageA

Image_Binarize

 

Input image.

imageB

Image_1

 

Input image.

imageAnd

Image_2

 

Store the result image of the "and operation" of two input images to this variable.

Image_Show

image

Image_2

 

Select the image variable you want to display.

displayPercentage

 

 

Displays the percentage of the image. A value of 200 means 200 (the image size is magnified one times), 50 means 50 (the image size is halved), and so on, zoom in and out.

windowTitle

windowTitle4

Image_2

The title of the window that displays the image. The window name is image_2.

 
 

【Generate an image of the cap cover tight】 The above steps have completely filtered out the cap (as shown in Fig. 15 below), and then use this image to make the cap that is tight. To connect the upper and lower parts of the cap, you can achieve this through the morphology of the image, as shown in Fig. 15 below.

 

Note: There are common types of erosion (erosion), dilation (expansion), Opening (disconnection), that is, the image erosion and then dilation, Closing (closed) that is, the image dilation and then erosion and so on. Fig. 16 below.

 

 

Fig. 15. Left is an image of the filter cap. Right is through the morphology to produce the cap is a tightly covered image..png

Fig. 15. Left is an image of the filter cap. Right is through the morphology to produce the cap is a tightly covered image.

 

 

Fig. 16. Above.png

Fig. 16. Above: the original image. The following figure is erosion, expansion, disconnection, and closure from left to right, respectively.

 

12 Image_Morphology

 

function

Variable name

name

value

use

Image_Morphology

image

Image_2

 

Enter the image variable.

morphologyMode

CLOSE

3

Sets which type operation to do.

0 : Erosion

1 : dilation

2 : open

3 : close

4 : Morphological Gradient

5 : Top Hat

6 :  Black Hat

kernelMode

int_1

1

0 : Rect

1 : Cross

2 : Ellipse

kernelSizeX

int_1

1

The left and right direction range of the morphology. The greater the value, the greater the effect.

kernelSizeY

Colse_Size_Y

35

The upper and lower direction range of the morphology. The greater the value, the greater the effect.

 

imageMorphology

Image_3

 

Store the processed image to this variable.

 
 

【Get the gap in the cap】Comparing the covered image of the cap with the image of the current cap, you can get the difference, that is, the gap in the cap. Fig. 17 below.

 

Then, because the remaining cap gap also shows the date of the cap we don't want (Fig. 17 left), then by the same technique as the filter bottle body above, the date is further filtered out by the blur and Binarization. Fig. 18 below.

 

Fig. 17. Left is the cap cover. The middle is the current image of the cap. Right is the cap gap image..png

Fig. 17. Left is the cap cover. The middle is the current image of the cap. Right is the cap gap image.

 

Fig. 18. The left image is a gap image of the cap. In the middle is the blurry image. The right is a binary image..png

Fig. 18. The left image is a gap image of the cap. In the middle is the blurry image. The right is a binary image.

 

13 Image_Diff

14 Image_Show

15 Image_Blur : Filter the print and noise above the bottle.

16 Image_Binarize

17 Image_Show

 

function

Variable name

name

value

use

Image_Diff

imageA

Image_3

 

Input image.

imageB

Image_2

 

Input image.

imageDiff

Image_3

 

The difference between image A and image B is saved to this variable.

mode

int_0

0

0 : A - B

1 : A – B, and then shift the average brightness to 128.

Image_Show

image

Image_3

 

Select the image variable you want to display.

displayPercentage

 

 

Displays the percentage of the image. A value of 200 means 200 (the image size is magnified one times), 50 means 50 (the image size is halved), and so on, zoom in and out.

windowTitle

windowTitle5

Image_3

The title of the window that displays the image. The window name is image_3.

Image_Blur

Image

Image_3

 

A source image for blur processing.

size X

Data18

85

In the left and right direction how much distance to do blur. The larger the value, the wider the blur distance.

size Y

Data19

1

How much distance to make blur in the upper and lower directions.

imageBlur

Image_4

 

The image is saved to this variable after the blur is done.

Image_Binarize

Refer to Image_Binarize file

image

Image_4

 

The source image that you want to make a binarization.

threshold

ThresholdValue_1

128

The threshold value of binarization.

imageBinarize

Image_4

 

Save the binary image to this variable.

Image_Show

image

Image_4

 

Select the image variable you want to display.

displayPercentage

 

 

Displays the percentage of the image. A value of 200 means 200 (the image size is magnified one times), 50 means 50 (the image size is halved), and so on, zoom in and out.

windowTitle

windowTitle6

Image_4

The title of the window that displays the image. The window name is Image_4.

 
 

【Definition and display results for setting the CAP without cover】This has been filtered to complete the gap image (left in Fig. 19 below). Locate the position coordinates of the medium white area through the Image_FindBlob, then draw the results on the image (in Fig. 19 below), and the window displays the message in JSON format (Fig. 19, right) below.

 

Fig. 19. Left is the filter complete gap image. The middle is the result image. Right is the result message..png

Fig. 19. Left is the filter complete gap image. The middle is the result image. Right is the result message.

 

18 Image_FindBlob  Grab the position where the gap height is greater than the threshold.

19 Json_Print

20 Image_DrawDefects

21 Image_Show

 

function

variable name

name

value

use

Image_FindBlob

 

Image

Image_4

 

Select the image variable you want to find the object. Enter a binary image to find the object.

enableMinX

 

 

 

minX

 

 

 

enableMaxX

 

 

 

maxX

 

 

 

enableMinY

True

1

A switch that sets a minimum height threshold.

minY

Min_Y_Gate

10

The minimum height threshold for an object. When the bottle cap gap is greater than this value, it means that there is no cover tight.

 

enableMinY

 

 

 

maxY

 

 

 

enableMinArea

 

 

 

minArea

 

 

 

enableMaxArea

 

 

 

maxArea

 

 

 

enableMinFillRate

 

 

 

minFillRate

 

 

 

enableMaxFillRate

 

 

 

maxFillRate

 

 

 

json

DefectJson

 

The result of the output to find out the area coordinates of the object in the image.

imageFrom

 

 

 

imageTo

 

 

The result of finding the object is drawn on the image.

type

NotTightened

NotTightened

The type name of the object that was detected.

Json_Print

Json

DefectJson

 

Displays the result message of the object above the window display.

Image_DrawDefects

image

Image_3

 

Enter the image. The rectangular content of the JSON string that you want to draw on this image.

json

DefectJson

 

Defective JSON messages.

imageDrawDefects

DefectJson

 

Place the defect box on the image to save this variable.

thickness

 

 

 

colorB

 

 

 

colorG

 

 

 

Color

int_255

255

The color of the rectangular box line.

extraRange

 

 

 

Image_Show

Image

Image_5

 

Select the image variable you want to display.

displayPercentage

 

 

Displays the percentage of the graph. A value of 200 means 200 (the picture is magnified one times), 50 means 50 (the picture is halved), and so on, zoom in and out.

windowTitle

windowTitle7

Image_5

The title of the window that displays the image. The window name is Image_5.

 
 

Recommended Article

1.
OpenR8 - AI Software for Everyone (Download)