7 min read

Machine vision is the field of equipping machines with the ability to perceive the real world through sight, enabling them to interpret their surroundings. Similar to how humans use their eyes and brains, vision systems use cameras and specialized software to capture images. They analyze the images (photos) to make decisions or to take actions based on the detected information.
In industry, a vision system can monitor the condition of products on a production line.
If a product has, for example, the wrong color or visible damage is detected, the system responds immediately by removing the defective item from the line, ensuring that only quality products proceed to the next stage.
The role of vision systems in modern industry is constantly evolving. These systems provide precise and reliable inspection and monitoring capabilities for a wide range of applications.
They are used where traditional sensors are inadequate, such as for detecting complex shapes, analyzing structural defects, identifying surface defects, inspecting product quality, or measuring dimensions. Vision systems are ideal for tasks that require visual interpretation and can adapt to changing conditions, providing consistent and objective results.
Precise foam detection is significant for industrial processes. It is crucial for:
- – process safety (preventing liquid overflows),
- – quality control (maintaining optimal conditions),
- – equipment protection (avoiding foam-related damage),
- – production efficiency (minimizing downtime),
- – preventing contamination (reducing foam spills, which can lead to contamination).
Foam detection vision systems can solve three main problems:
- – determine whether foam is present in the tank (binary detection – a “yes” or “no” answer),
- – measure the height of the foam level (level detection, as with a measuring instrument),
- – analyze the structure and color of the foam (e.g., bubble size and color analysis).
Solutions to these problems enable factories to operate safely and efficiently by continuously monitoring their processes.

Traditional Methods of Foam Detection
For years, the industry has relied on three main types of foam sensors, each with significant limitations in binary and level detection.
Although traditional sensors have been used for decades, they often struggle to provide consistent and reliable measurements in dynamic industrial environments.
Conductivity sensors
Conductivity sensors work by measuring the electrical conductivity between electrodes. When foam touches the electrodes, it changes the conductivity, triggering an alarm.
Capacitive sensors
Capacitive sensors measure changes in capacitance to detect the presence of foam. They create an electric field between the sensor and the tank wall. Growing foam constantly changes the
Ultrasonic sensors
Ultrasonic sensors use sound waves to detect foam. They emit ultrasonic pulses and measure the time it takes for the echo to return. However, they have difficulty obtaining accurate results due to the way foam interacts with sound waves.
Sensor type | How does it work? | Best applications |
---|---|---|
Conductometric | – two electrodes in the tank – foam closes the circuit – sensor signals foam presence | – conductive liquids – binary detection – basic monitoring |
Capacitive | – sensor generates an electric field – foam changes capacitance – sensor detects the change | – non-conductive liquids – presence and level detection – clean, stable enviroments |
Ultrasonic | – sensor emits ultrasonic pulses – pulse reflects off the foam – return time converted to foam level | – non-contact mesaurement – binary and level detection – large tanks |
Typical problems of traditional methods.
Traditional foam detection methods face several significant challenges that limit their effectiveness in industrial environments. In binary detection, sensors often have high false alarm and missed detection rates, making them unreliable in variable process conditions.
Their performance is further compromised by their susceptibility to environmental factors and poor adaptation to complex or changing process scenarios.
In level detection, traditional sensors typically offer limited measurement accuracy and struggle to distinguish foam levels in dense or variable foam types. Over time, drift in calibration can degrade their precision. Operational sensors require frequent maintenance and can be challenging to install, especially inside dynamic and unpredictable processes.
Their suitability in demanding industrial conditions is limited by their inability to adapt to process changes and the risk of breakdowns when in direct contact with foam.
Foam detection vision systems
Two main algorithmic approaches are used in vision systems for foam detection: traditional mathematical methods and modern machine learning techniques
Mathematical methods are based on classic image processing techniques such as thresholding and edge detection, while machine learning methods use pattern recognition and neural networks. Each approach has its own unique advantages. Mathematical methods offer transparency and predictability of results, while machine learning excels in complex, variable conditions.
How to prepare the image?
Image preparation for foam detection begins with loading the camera image into the computing environment, often using the OpenCV library. The image is usually cropped at this stage to standardize the resolution and focus only on the relevant working area only. This saves computing resources in subsequent steps. A standard colorful image or (camera frame) consists of three channels – red, green and blue. It is common practice to convert the image to grayscale. This simplifies calculations by combining the three color channels into a single intensity value for each pixel, effectively reducing the image to a single array and streamlining further processing.
After conversion to grayscale, a Gaussian blur reduction filter is applied to minimize the impact of random errors or artifacts that may be present in the image. In some cases, the contrast of the image is enhanced to make its essential features more visible. The final step is normalization, which adjusts pixel values to a consistent range. This allows images taken under different lighting conditions or with different exposures to be processed uniformly.
Mathematical Approaches to Foam Detection
These approaches are based on classical image processing techniques. These methods convert raw camera images into usable detection results. They are deterministic, meaning their performance is predictable, and the results are easy to interpret and adapt to specific industrial needs.
Thresholding
Thresholding analyzes the image by setting a specific threshold intensity value to separate the foam from the background. Pixels above or below this threshold are classified as foam or non-foam. This method is effective when there is a clear contrast between the foam and its surroundings.
Edge Detection
Edge detection identifies foam boundaries, highlighting areas of the image where there is a sudden change in intensity. This allows the system to outline the shape and size of the foam, which is helpful for both detection, presence, level, and structure.
Thresholding and Edge Detection
The combination of thresholding and edge detection helps improve the accuracy of foam detection. First, thresholding enables the isolation of relevant areas, and then edge detection is applied to these portions of the image to determine foam boundaries and levels accurately. This hybrid approach combines the advantages of both techniques, resulting in a more robust system even under harsh conditions.
Machine Learning Methods:
Machine learning methods for foam detection use data-driven algorithms that recognize complex patterns in images. This allows them to work well in environments where the appearance of foam, lighting conditions, or background can change. Unlike traditional mathematical approaches, these techniques can adapt to new scenarios by learning from representative datasets.
K-means
The K-means algorithm is one of the most popular unsupervised clustering methods. It groups pixels in an image based on their similarity in terms of intensity or color, for example. In foam detection, k-means allows segmentation into areas corresponding to foam and background, and does not require labeled training data to operate. This approach is efficient during initial segmentation or when labeled data is unavailable, though the resulting clusters may require further interpretation.
Support Vector Machines (SVM)
Support Vector Machines (SVM) are supervised learning models that classify data by determining the boundary (hyperplane) separating different classes. In foam detection, SVMs are most commonly used after first extracting features from an image, such as texture, edge patterns, or statistical measures. The method is particularly effective in binary classification tasks and performs well with smaller datasets, but its performance largely depends on the quality of the selected features.
Convolutional Neural Networks
Convolutional Neural Networks (CNN) are a type of deep learning designed specifically for image analysis. The networks can autonomously extract relevant features from raw data, making it possible not only to detect the presence of foam but also to measure its level accurately. CNNs excel at dealing with differences in foam structure, varying lighting conditions, and different camera perspectives.
It is worth remembering that supervised machine learning methods require large amounts of labeled data for training and validation, and their decision-making process can sometimes be less transparent than traditional mathematical approaches. They also typically require more computational resources, especially during the learning phase.
Modern foam detection systems that use both machine learning and classical image processing techniques can achieve high accuracy and robustness, matching the requirements of industrial applications.
Key parameters of vision systems
When designing and implementing vision systems for foam detection, several vital parameters must be considered to ensure reliable and accurate operation in an industrial environment.
Industrial cameras and resolution
The quality of the incoming image is fundamental to the effectiveness of any video system. High-resolution industrial cameras can capture more detail, resulting in more precise detection and measurement of foam. However, higher resolution increases the amount of data and computational requirements, so a compromise must be found, depending on the application’s needs. Additional features, such as autofocus or a global shutter, can enhance image quality and improve system responsiveness. It’s also worth remembering that in industrial applications, vision systems often need to feature high resistance to dust and varying temperatures, and provide trouble-free operation for extended periods without requiring a reboot.
Stable illumination
Stable illumination is crucial for the operation of vision systems. Changes in light intensity or reflections from surfaces can cause artifacts, thereby reducing the accuracy of analysis. The use of additional light sources (e.g., LED panels) or backlights (for contrast enhancement) can maintain high image quality regardless of external conditions. The system should be designed to minimize the impact of illumination changes due to the diurnal cycle or process variations.
Mounting and positioning of the camera
The camera must be mounted stably and solidly to eliminate any movement that could cause blurred images and reduce measurement accuracy. It should be placed outside the workers’ movement zone to avoid accidental obstruction or interference with the field of view. Complete, uninterrupted visibility of the monitored object is crucial. Proper positioning ensures that the foam area is recorded at the correct angle, minimizing perspective distortion.
Video calibration
Calibration is necessary to convert pixels into real units (e.g., millimeters or centimeters). It usually involves placing reference markers or objects of known dimensions in the camera’s field of view. Calibration also enables the correction of lens distortion and perspective effects, ensuring that foam level measurements are less dependent on camera positioning.
Clear environment
For vision systems to work reliably, the camera must have a clear view of the monitored area. The space in front of the lens should be kept clean and free of dust, fogging, or other contaminants that could degrade image quality. Ensuring a clear optical path allows the vision system to detect foam and minimize the risk of false readings accurately. In foam measurement applications inside tanks, the process itself (e.g., a bioprocess) can significantly reduce the visibility of the tank’s interior walls, posing additional challenges for the system.
Compromises and system optimization
It is often necessary to find a compromise between image quality, processing speed, and system cost. In some applications, it may be more advantageous to capture a smaller number of high-quality images than to acquire a large number of lower-quality images. The system should be optimized for specific detection requirements, available infrastructure, and serviceability.
Industrial Systems Integration
In the era of Industry 4.0 and the Industrial Internet of Things concept, it is crucial to ensure seamless connectivity and integration of all devices in an industrial network, including vision systems. IIoT refers to the interconnection of machines, devices, and systems via digital networks, enabling remote monitoring, data analysis, and real-time process automation.
Modern solutions for detecting foam are integrated with other inventory systems, machines, PLCs, and PCs, rather than being isolated from them. They can communicate with other processes and system functions. This integration enables real-time monitoring and rapid response to process changes, allowing for swift adjustments to ensure optimal performance. For example, if the system’s video surveillance equipment detects a high level of noise, it can automatically alert operators via the SCADA system or mobile devices. It can also trigger automated logic to limit risk.
Connecting video systems to industrial networks
A typical video system consists of a computer and an industrial camera. The camera must be properly connected and recognized by the computer (on Linux systems, it may appear as a `/dev/video1` type device). Once the hardware is configured, a vision application can be implemented, often developed using libraries such as OpenCV. The application typically involves four main steps: camera image acquisition, image preprocessing, image analysis, and transmission of results to external systems.
There are many ways to send detection results to the broader industrial environment. Communication standards, such as RS-232 and RS-485, as well as protocols like Modbus and CAN, are commonly used in OT systems to integrate detection results with the broader industrial environment.

However, for greater flexibility and integration with modern automation systems, a direct software connection to an MQTT broker or OPC UA server is used. These protocols support real-time data exchange, interoperability, and scalability, making them ideal for Industry 4.0 applications. Python language implementations can utilize the `paho-mqtt` library to communicate with MQTT brokers, and the `opcua` library to interact with OPC UA servers. It is worth remembering that vision systems are full-fledged industrial solutions. The parameters they generate, such as foam height or presence, should be considered industrial-grade measurement values.
The application can enrich the transmitted message with relevant metadata, such as the device name, the monitored object ID, the value type, the timestamp, and other pertinent information. This approach provides context for each measurement. For advanced integration and future scalability, these values, along with metadata, can be encapsulated according to the Module Type Package (MTP) standard, facilitating interoperability and scalability in modular and evolving industrial environments.
Summary
The deployment of modern industrial vision systems is not only an answer to the current challenges of foam detection, but also a step towards the future of automated and intelligent manufacturing. Integrating advanced technologies such as image analysis, machine learning, and IIoT communications opens up new opportunities to optimize processes, enhance safety, and improve product quality. Investing in innovative vision solutions is a step towards increasing competitiveness and business growth. It is worthwhile to continually seek new applications and improve the systems being implemented to fully leverage the potential offered by the digital transformation of the industry.