I am an automation engineer with experience in PLC, DCS, industrial process controllers, and SCADA systems. I am also a hobbyist who enjoys working with Arduino, Raspberry Pi, 3D printing, CNC, and IoT devices. As part of my hobby, I have been learning OpenCV, a computer vision library.
I recently used OpenCV to solve a practical problem in an industrial application. I am sharing my experience with the community so that others can see how OpenCV can be used to solve real-world problems.
I am excited to see how OpenCV can be used to improve industrial automation
processes in the future. I believe that OpenCV has the potential to make automation more efficient, accurate, and reliable.
To understand this project better, let's first look at where it has been implemented and how it works.
This system has been implemented to protect belt conveyors that are used to handle cargo from one location to another. The conveyor belt speed is quite high, at 4.2 meters per second. The cargo being handled is coal and gypsum, and metal objects are often received along with the cargo, as it is being processed by mining equipment. These metal objects can damage the belt if they get stuck in the conveyor.
There have been many instances of belt ripping due to foreign material getting caught between the suspended magnet and the conveyor belt. This can lead to significant costs, both in terms of replacing the belt and the downtime caused by the repair.
How belt got damaged is explained as below.
Occasionally, extended metal objects inadvertently accompany the cargo, entrapped by the magnetic system. In such instances, only one end of these metal parts is securely held by the magnet, while the other end becomes ensnared within the coal payload. The force exerted by the conveyor, designed to facilitate smooth cargo movement, initiates a destructive process. This results in the gradual rupture of the conveyor belt. The belt, being composed of rubber, responds to this force like a knife cutting through soft butter. The dynamics of this scenario are further illustrated in the attached screen image below
Idea what we came up with is to use CCTV camera feed to analyze image of conveyor belt. This digital image data will further process by python script which can derive meaning full information from that image and generate alarm in case of any obstacle observed between belt and magnet.
System implementation and working:-- First Step Camera Installation: Placing IP cameras in front of the conveyor belt in such way it can have magnet and belt both in single frame. by this we can detect void space between conveor and manget. our aim is to trigger alarm if anyting is there between belt and magnet.
- Second Step :-installation of unique Colored Plate in front of camera. The use of a unique colored plate to generate a mask on the image is a clever way to create a reference point for image analysis. It helps in detecting any deviations caused by foreign objects. i have used blue, green and white but yellow is perform very.
- Third step:-Reading Image frame data and creating RIO. Image frame is read using RTSP stream of IP camera.
ret, frame = camera.read()
- Forth Step:- Create ROI using perspective wrapping function of OpenCV. Yellow plate in frame is not prefect rectangle hence I have used perspective wrapping function to generate proper rectangle. Frame data is in BGR format which is converted to HSV so I can perform masking in next step.
framehsvwrp = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
matrix = cv2.getPerspectiveTransform(pt1,pt2)
output = cv2.warpPerspective(framehsvwrp,matrix,(width,height))
- Fifth Step:- Mask is applied on ROI. Value for masking is derived by trail and error method and final value is hardcoded in script. future plan is to include scrollbar in running script to adjust masking value in live feed.
masked = cv2.inRange(output,maskL,maskH)
- Fixth step:- is to detect contours form masked image using chain approximation method. contours are sorted to get largest contour in first place IN array. first contort width and height is then calculated for to get area of contour.
contours, hierarchy = cv2.findContours(masked,cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
contours = sorted(contours,key=cv2.contourArea,reverse=True)
wrapped_contor,Wrapped_area,Wrapped_width = 0,0,0
for cnt in contours:
area = cv2.contourArea(cnt)
if wrapped_contor == 0:
_,_,wrp_wdt,_ = cv2.boundingRect(contours[0])
Wrapped_area = area
Wrapped_width = wrp_wdt
wrapped_contor = wrapped_contor+1
cv2.imshow("output",output)
cv2.imshow('masked', masked)
- Seventh step:- In this step lots of calculations are carried out. first is to exclude contours having below 1000. then applying lowpass filter to get stable value of area and width. only first contour area and width is then stored in local variable.
for i,cnt in enumerate(contours):
#Counting total countors by looping loop count
total_conours = total_conours+1
#Extrecting area of countour
area = cv2.contourArea(cnt)
#validating contor area before processing its value
if(area >1000):
#Calculating new area by aplying lowpass filter
new_a1 = (area*0.01 + new_a1*0.99)
#Extrecting cordinates for countour
xb1,yb1,wb1,hb1 = cv2.boundingRect(cnt)
#Converting area and widht of countor from int to string for display on frame
msg = "Pixel Area:" + str(area)
msg2 = "Safe Length:"+ str(wb1)
#Displaying Area and Width of contour on frame
cv2.putText(frameroi,str(msg),(xb1,yb1),cv2.FONT_HERSHEY_COMPLEX,0.5,red,1)
cv2.putText(frameroi,str(msg2),(xb1+int(wb1/2),yb1+int(hb1+5)),cv2.FONT_HERSHEY_COMPLEX,0.5,green,1)
#Draw countor on original frame
cv2.drawContours(frameroi,[cnt], -1, red, 1)
#Extrecting first countor width
if total_conours > 0:
_,_,w2,h2 = cv2.boundingRect(contours[0])
box_Width1 = w2
box_ht1 = h2
# Extracting second contor
if total_conours >1:
_,_,w3,h3 = cv2.boundingRect(contours[1])
box_width2 = w3
box_ht2 = h3
#Calculating new width by aplying lowpass filter
new_w1 = (wb1*0.05) + (new_w1*0.99)
if (indx <= avg_size):
arr[indx] = cv2.contourArea(contours[0])
arr1[indx] = wb1
indx = indx+1
if (indx == avg_size):
indx = 0
area_per = int((np.sum(arr)/avg_size)*100/25000)
width_per = int((np.sum(arr1)/avg_size)*100/300)
weight = int(area_per*0.1+ width_per*0.9)
- Eighth Step:- Finally all filtered values along with some other values are converted in json string and published to MQTT broker.
msg= {"FPS":fps,"area":area/10,"run_avg":int(np.sum(arr)/avg_size)/10,"Box_W":wb1/2,"run_avgw":int(np.sum(arr1)/avg_size)/2,"weight":weight,"Wrapped_area":Wrapped_area,"Wrap_Wdt":Wrapped_width}
msg = json.dumps(msg)
#Posting Json packet to mqtt broker
result = client.publish(topic, msg)
- Ninth Step:- To push area and width data to industrial application like SCADA I have used MQTT to OPC gateway application which is Kep server. KepServer is installed on SCADA server. it is connected with MQTT broker and subscribed to topic on which python script published data.
- Final Step :- Once width and area is transferred in to Wincc tag I have write small c script to compare live area and width data with thresold value and if it is less then thresol then alam is generated and Camera feed si overlay on wincc SCADA Client. Control room operator then check live camera feed and if he/she found any thing abnormal he/she stop conveyor and inform field engineer to remove that object.
The project to develop a system to protect belt conveyors from metal objects using OpenCV was a success. The system was implemented in a real-world industrial setting and has been very effective in preventing belt damage and improving safety.
The system has saved the company significant money in terms of belt replacement costs and downtime. It has also helped to improve the safety of the workplace by preventing accidents caused by metal objects getting stuck in the conveyors.
The success of this project demonstrates the potential of OpenCV to be used to solve real-world problems in industrial automation. By detecting metal objects on conveyor belts, the system helps to protect the belts from damage and improve safety.
The system is also scalable and can be adapted to meet the needs of a wide range of industries. For example, the system could be used to protect conveyor belts used to transport food, pharmaceuticals, or other sensitive materials.
The project team is excited to continue to develop and improve the system. They are also working to develop new applications for OpenCV in industrial automation.
Comments