A Report of Line Detecting Program
A Report of Line Detecting Program
Method
In general, the main function of the program includes image processing, get region of
interest (roi) of each frame, contour capturing, coordinate marking, and video exporting
(as shown in figure 1).
The image processing step was designed to convert the original images to binarized
frames. The roi selecting was applied to crop the images to tiny parts for analysing.
Based on the region of interest, contour will be accessed so an appropriate coordinate
of each frame could be computed. Eventually, the computed coordinates were marked
by “coordinate marking” section.
In image processing part, initially the original image was resized so the full image could
be shown on the screen (otherwise, only part of the images could be shown). Track
bars were afterwards used to figure out the appropriate HSV value for image
binarization (track bar related codes were commented, and some parts might be
missing).
The binarized image was then cropped to access the ROI (480 pixels wide, 1 pixel
high, shown in figure 2) of the image and the ROI processed image was exported for
further computation.
In the processed image, the contour was accessed, left extreme point and left extreme
point was figured out based on the contour, so horizontal center of the contour was
accessed by taking average value:
𝑥𝑙𝑒𝑓𝑡 + 𝑥𝑟𝑖𝑔ℎ𝑡
𝑥𝑚𝑖𝑑𝑑𝑙𝑒 =
2
𝑦𝑚𝑖𝑑𝑑𝑙𝑒 = 150 (𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡)
The y-axis coordinate was kept 150 since the y-axis coordinate of ROI was the
constant 150.
In information printing section, horizontal center of the black track was highlighted with
red dot and the coordinates was printed on each frame of the video.
To detect the out of view circumstance, 4 surrounding points (shown in figure 6) were
defined. In binarized figures, if all the surrounding point coordinates have the color of
white, then “out of view” would be printed on the screen. Otherwise, normal information
would be shown.
The upper point, lower point is 37 pixels, 16 pixels from the center point respectively.
The left point, right point is 35, 5 pixels from the center point. The reason that the
distances are different will be stated in “discussion” part.
The color value was extracted from a scalar and stored in an integer, 0 represents
white and 255 stands for black. Hence if all 4 values are 0, then the message “out of
view” would be shown.
Figure 7. Flow chart of information printing section
Loop was already used in main function; Therefore, loop was not used in any other
sections.
Result
In the processed video, the position of central point and the related information can be
shown accurately and when there is no black track, “out of view” was printed.
There are still issues remains, when a right angle was detected, the coordinate should
only have tiny changes, but it changes quite significantly and frequently. The reason is
that in the frames which a right angle was detected, there are more than 1 contour.
However, only the central point for the first contour could be shown.
Another issue is that the “out of view” message shown up appears be too late, there
are a few frames still printing incorrect point information rather than “out of view”
message. Such circumstance was caused by the distance of the lower point from the
central point.
Figure 10. Out of view anomaly detection
Discussion
The initial idea is to fix 4 surrounding points, and they have equivalent distance from
the central point. But there are times when horizontal coordinate of central point is
quite large (around 474). Since the width of the image is only 480 pixels, the right point
cannot be too far from the central point.
The distance between lower point and central point cannot be too large either,
otherwise “out of view” message would be shown up much later.
Gaussian Blur was applied when testing the code to solve the issue that there are
moments when contour number is more than 1. However, the previous problem was
not solved, and there are even more frames which there is no contour.
To estimate, the program can locate the central point in a relatively high accuracy. But
it performs poorly in special circumstances such as right angle and “out of view”
phenomenon.
Appendix I
https://nottinghamedu1-
my.sharepoint.com/:v:/g/personal/ssyxz10_nottingham_edu_cn/EcpCLnREbfNGjXqzr
Peaij4B6aq7nlHfJKVk7_j2VUYLKA?e=e5iiCO
Appendix II
https://nottinghamedu1-
my.sharepoint.com/:u:/g/personal/ssyxz10_nottingham_edu_cn/EbPIpNRFraNArRTH
__3tVKUBRgFRom91vPRYaJKTeok4YQ?e=2ypUzf