Visual System for Casting Defect Detection

I have developed a machine vision system for casting surface defect detection because casting defect inspection remains one of the most difficult and important tasks in modern precision manufacturing. In my work, I treat casting defect detection not as a simple image classification problem but as a complete industrial vision task that includes image acquisition, target extraction, defect enhancement, interference suppression, software integration, and real-time testing. The central goal of my system is to detect surface defects on plate teeth produced by a casting process, save images of defective parts for later review, and send a rejection signal to the production line. Because some casting defects are difficult or impossible to identify reliably by direct human observation, I used magnetic particle adsorption and fluorescent illumination to make the casting defect regions visible. However, long-term direct viewing of fluorescent light can cause irreversible damage to human eyes, so an automated visual system for casting defect detection is highly desirable in this industrial context.

From my perspective, the most important reason for developing this system is that manual inspection of casting defect locations is inconsistent, slow, and potentially harmful. A human inspector may become tired, may be influenced by subjective judgment, and may fail to notice small or low-contrast casting defects. A machine vision system can operate continuously, can apply the same decision rule to every part, and can store defect images for traceability. In my design, I therefore combined hardware selection, image preprocessing, target extraction, line-based casting defect extraction, and a user-friendly software interface. I also paid close attention to real-time performance because the production line requires a detection cycle of no more than 300 ms per part. The system I developed is intended to allow a small number of false positives but no missed casting defects, because a missed casting defect can cause serious quality problems in later use.

The general appearance of casting defects can vary widely, and a visual reference is useful when explaining why detection is challenging. The following image shows typical casting defect patterns that motivate the need for careful illumination and robust image processing.

In my project, the casting defect of interest is mainly a crack-like or line-like discontinuity generated during the casting and pressing process. These casting defects usually occur near the two circular rings of the plate tooth. Under ordinary illumination, the casting defect is almost invisible. Under fluorescent magnetic particle inspection, the casting defect becomes brighter or differently colored compared with the surrounding surface. Therefore, the vision system must not only capture the image but also enhance the casting defect while suppressing the natural texture of the casting. The natural texture of the casting is highly similar to the casting defect in gray level and shape, which makes the separation task difficult. I designed the algorithm so that line-like casting defects can be extracted while most texture interference is rejected.

I began with a requirement analysis. The production line required that the casting defect detection cycle be completed within 300 ms. The system had to save images of defective parts, allow false positives at a rate below 0.1%, and avoid missed casting defects. The system also had to be compatible with the existing production line. I summarized the requirements in the table below.

Requirement Target value Reason
Detection time per part ≤ 300 ms Match production line cycle
Defect image storage Required Support later review and system improvement
False positive rate ≤ 0.1% Reduce unnecessary rejection
Missed casting defect rate 0% allowed Defective parts must not pass
Line integration Required Work with existing casting process
Operator safety Required Avoid direct fluorescent light exposure

I identified three major difficulties. First, ordinary lighting does not reveal the casting defect clearly. Second, the casting defect must be extracted from a textured surface with many interfering edge fragments. Third, the algorithm must be robust enough to handle different plate teeth without changing parameters for every part. I addressed these difficulties by using fluorescent magnetic particle enhancement, selecting appropriate industrial hardware, applying median filtering, using shape-based template matching for target extraction, and designing a line-based casting defect detection method with interference removal.

Before I describe the detailed algorithm, I should state the overall system architecture. My system consists of an image acquisition subsystem, a machine vision processing subsystem, a display subsystem, and a software subsystem. The image acquisition subsystem contains a camera, lens, light source, and industrial computer. The machine vision processing subsystem performs target extraction and casting defect detection. The display subsystem shows the current image and the inspection result. The software subsystem manages user permissions, camera settings, parameter storage, automatic operation, and result logging. The overall relationship is summarized below.

Module Function Main output
Image acquisition Capture the part image under fluorescent illumination Color image
Preprocessing Reduce noise and extract useful channel Smoothed gray image
Target extraction Locate the plate tooth in the image Region of interest
Casting defect detection Extract line-like casting defects Defect contour and position
Software interface Provide user operation and parameter control Detection result and saved image
Production line communication Send rejection signal Reject command

For the hardware selection, I considered resolution, sensor type, target size, trigger mode, and industrial environment. I needed enough resolution to detect a casting defect whose width could be very small. The plate tooth is about 10 cm long and 4.5 cm wide. I selected a camera with a resolution of 2058 × 2488 pixels, which provides a physical pixel size close to 0.04 mm in the field of view. I chose a CCD sensor because it offers good sensitivity and low noise. I chose a color camera because the casting defect appears more clearly in the green channel under fluorescent illumination. I used a hardware trigger because the camera must capture the image when the part reaches the inspection position. The hardware configuration is listed in the table below.

Device Selection Key reason
Industrial camera Color CCD camera, 2058 × 2488 High resolution and green-channel defect contrast
Lens Manual zoom lens, GMHR-0814MCN type Adjustable focus and field of view
Light source Fluorescent source with side illumination Reveal magnetic particle indication
Industrial computer RPC-910 type Stable operation in industrial environment
Trigger Hardware trigger Capture at correct position
Background White background plate Improve segmentation stability

I paid special attention to focus. In my experiments, changing the focus distance changed the visibility of the casting defect. When the focus was set too close to the ideal surface focus, the plate tooth surface was sharp but the casting defect was blurred. When the focus was shifted slightly, the surface became less sharp but the casting defect became more visible. I selected the focus setting that sacrificed some surface sharpness in order to preserve the casting defect signal. This choice is reasonable because my algorithm depends on the presence of line-like casting defects rather than on the fine texture of the casting surface.

The acquisition process is also important. In my production-line setup, a conveyor moves the plate tooth to a specified position. An infrared sensor detects the part and stops the conveyor. A manipulator picks up the part and places it on an electrode for magnetization and magnetic suspension spraying. Another manipulator then moves the part to the inspection position. The electrodes clamp the part, and the camera captures the image under fluorescent illumination. This sequence ensures that the casting defect is enhanced before image acquisition. The whole inspection depends on stable positioning, but the system still needs template matching because the part can shift slightly between cycles.

For image preprocessing, I first split the original RGB image into red, green, and blue channels. I observed that the casting defect has the best contrast in the green channel. Therefore, I used the green channel for subsequent processing. I then examined the image noise. Under magnification, the green channel contained salt-and-pepper noise. I compared several spatial filters: median filtering, mean filtering, and Gaussian filtering. The median filter was the best choice for my project because it removes salt-and-pepper noise effectively while preserving edges. I also tested different filter masks. A rectangular mask of size 1.5 × 1.5 gave the best balance: it removed the salt-and-pepper noise and preserved the casting defect. A circular mask of radius 1 preserved the casting defect but left too much noise. A larger rectangular mask removed more noise but also weakened the casting defect. The comparison is summarized below.

Filter Mask or parameter Effect on casting defect Decision
Median filter 1 × 1 rectangular Little noise removal Rejected
Median filter 1.5 × 1.5 rectangular Good noise removal, defect preserved Selected
Median filter Circle radius 1 Defect preserved, noise remains Rejected
Median filter Circle radius 1.5 Defect weakened Rejected
Mean filter Small rectangular Edge blurred Rejected
Gaussian filter Small kernel Smoothing too strong Rejected

Mathematically, the median filter replaces the center pixel with the median value in the neighborhood:

$$g_{r,c} = \mathrm{med}\{f_{k,l}\mid (k,l)\in W\}$$

Here, \(g_{r,c}\) is the output pixel, \(f_{k,l}\) is the input pixel, and \(W\) is the filter window. The mean filter computes an average:

$$g_{r,c} = \frac{1}{m}\sum_{(k,l)\in W} f_{k,l}$$

The Gaussian filter uses a weighted kernel based on the Gaussian function:

$$G(x,y)=\frac{1}{2\pi\sigma^2}\exp\left(-\frac{x^2+y^2}{2\sigma^2}\right)$$

For my casting defect detection task, the median filter with a 1.5 × 1.5 rectangular mask produced the most reliable preprocessing result. I used this result as the input to the target extraction stage.

I explored two target extraction methods for the casting defect inspection system: Blob analysis and template matching. Blob analysis is based on segmenting an image into regions that share similar properties such as color, texture, or gray level. It is widely used for presence detection and defect detection when the background and foreground can be separated. The general Blob analysis workflow is acquisition, segmentation, and feature extraction. In practice, however, the segmentation step is often the most difficult because the foreground and background may have overlapping gray levels. In my casting images, the plate tooth and the background had overlapping intensities, so simple thresholding did not work. I then considered dynamic threshold segmentation, which compares each pixel with a local background estimate. For bright objects, the dynamic threshold condition is:

$$S=\{(r,c)\in R \mid f_{r,c}-g_{r,c}\ge g_{\mathrm{diff}}\}$$

For dark objects, the condition is:

$$S=\{(r,c)\in R \mid f_{r,c}-g_{r,c}\le -g_{\mathrm{diff}}\}$$

Here, \(f_{r,c}\) is the original gray value, \(g_{r,c}\) is the smoothed local background, and \(g_{\mathrm{diff}}\) is the difference threshold. I tested dynamic threshold segmentation with different filter sizes. A filter size of 1500 × 2500 was too large and caused the background pipe to merge with the plate tooth. A filter size of 50 × 2000 worked for some images but was not general. I therefore added a white background plate and adjusted the illumination. This modification improved segmentation stability. After dynamic thresholding, I filled the regions and extracted the region with the largest area. This allowed me to crop the plate tooth from the image. Although Blob analysis could extract the plate tooth in many cases, the extracted boundary was sometimes incomplete, especially when reflection or illumination changed. This incomplete boundary created problems for the later casting defect detection stage.

Template matching was the second target extraction method I studied. Template matching searches an image for the location that best matches a template. Three main types exist: gray-value-based matching, edge-based matching, and shape-based matching. Gray-value-based matching uses similarity measures such as the sum of absolute differences (SAD) or the sum of squared differences (SSD). The SAD measure is:

$$SAD_{r,c}=\frac{1}{n}\sum_{(u,v)\in T}|t_{u,v}-f_{r+u,c+v}|$$

The SSD measure is:

$$SSD_{r,c}=\frac{1}{n}\sum_{(u,v)\in T}[t_{u,v}-f_{r+u,c+v}]^2$$

These measures work well when illumination is stable, but they are sensitive to lighting changes and color variation. To reduce sensitivity to linear illumination changes, normalized cross-correlation (NCC) can be used:

$$NCC_{r,c}=\frac{1}{n}\sum_{(u,v)\in T}\frac{t_{r,c}-m_t}{s_t}\cdot\frac{f_{r+u,c+v}-m_{f,r,c}}{s_{f,r,c}}$$

Here, \(m_t\) and \(s_t\) are the mean and standard deviation of the template, while \(m_{f,r,c}\) and \(s_{f,r,c}\) are the mean and standard deviation of the corresponding image region. NCC is more robust to linear illumination changes because it subtracts the mean and divides by the standard deviation.

I also considered image pyramids to accelerate matching. A pyramid reduces the number of pixels at each higher level. The relationship between pyramid level and search speed is shown below.

Pyramid level Pixel reduction factor Search speed relative to original
1 1 1
2 4 16
3 16 256
4 64 4096
5 256 65536

Edge-based matching extracts contours and compares them with template contours. It can handle partial occlusion and nonlinear illumination changes, but it depends heavily on edge extraction quality. Shape-based matching is more robust. It uses gradient direction information and can handle partial occlusion, nonlinear illumination, and anisotropic scaling. Since the plate teeth can vary slightly in size and can appear at slightly different angles, I selected shape-based matching with anisotropic scaling. I created a template from a defect-free region of a plate tooth. When creating the template, I set the pyramid level, start angle, angle range, angle step, minimum and maximum scale, scale step, template optimization, polarity, and contrast. The most important matching parameters are listed below.

Parameter Meaning Typical setting in my system
Pyramid level Number of pyramid layers Selected by experiment
Start angle Initial search angle Based on mechanical positioning
Angle range Allowed angular deviation Small range to reduce search time
Angle step Angular search increment Fine enough for small rotations
Scale range Minimum and maximum scale Handles part size variation
Scale step Scale search increment Balances speed and accuracy
Min score Minimum accepted match score High enough to reject false matches
Number of matches Maximum matches returned Usually one
Max overlap Allowed overlap between matches Prevents duplicate matches

During my initial tests, matching failed when the plate tooth changed or when its position shifted. I analyzed the problem and found that different plate teeth had large differences in fine surface detail. To improve robustness, I smoothed the image before matching. This removed fine details and preserved the overall contour. The match score increased by about 0.1 after this step. I then used the match result to locate the plate tooth. Because template matching returns the row, column, and angle of the match, it does not directly produce the whole plate tooth region. I therefore recorded a region of interest (ROI) around the plate tooth when creating the template. After matching, I computed an affine transformation from the template pose to the current pose and used it to move the ROI. The affine transformation can be written as:

$$\begin{pmatrix} Row \\ Column \\ 1 \end{pmatrix} = HomMat \cdot \begin{pmatrix} Row_1 \\ Column_1 \\ 1 \end{pmatrix}$$

The translation and rotation components are:

$$\begin{pmatrix} Row \\ Column \\ 1 \end{pmatrix} = \begin{pmatrix} 1 & 0 & \Delta Row \\ 0 & 1 & \Delta Column \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} Row_1 \\ Column_1 \\ 1 \end{pmatrix}$$

$$\begin{pmatrix} Row \\ Column \\ 1 \end{pmatrix} = \begin{pmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} Row_1 \\ Column_1 \\ 1 \end{pmatrix}$$

Combining translation and rotation gives the homogeneous matrix:

$$HomMat = \begin{pmatrix} \cos\theta & -\sin\theta & \Delta Row \\ \sin\theta & \cos\theta & \Delta Column \\ 0 & 0 & 1 \end{pmatrix}$$

Here, \(\Delta Row = Row_1 – Row\), \(\Delta Column = Column_1 – Column\), and \(\theta = Angle_1 – Angle\). This matrix allows the ROI to follow the internal contour of the plate tooth even when the part shifts or rotates.

I compared Blob analysis and template matching for target extraction. Blob analysis could extract the plate tooth in some images, but the boundary was sensitive to illumination and surface reflection. Template matching produced a more stable and complete region for different plate teeth. The comparison is summarized below.

Method Advantage Disadvantage Decision
Blob analysis Simple segmentation concept Sensitive to illumination and reflection Rejected for final system
Dynamic threshold Blob Better than fixed threshold Filter size not general for all images Rejected for final system
Gray-value template matching Simple and fast in stable light Sensitive to illumination and color changes Rejected
Edge-based matching Handles partial occlusion Depends on edge extraction quality Rejected
Shape-based matching Robust to illumination and scaling Requires template creation and tuning Selected

After target extraction, I focused on casting defect detection. The casting defect in my task is generated during pressing and appears as a line-like crack near the two circular rings. Therefore, I designed a line-based casting defect detection algorithm. The central idea is to extract line-like structures from the image, remove small interference, merge broken line segments, and select long lines as casting defects. This approach is suitable because the casting defect is elongated, while most surface texture fragments are short. However, the outer and inner contours of the plate tooth also appear as long lines and can be mistaken for casting defects. I therefore removed both the outer contour and the inner contour before line extraction.

For outer contour removal, I used morphological erosion. In binary region processing, erosion shrinks a region. If \(R\) is the input region and \(S\) is the structuring element, erosion is defined as:

$$R\ominus S = \bigcap_{s\in S} R_{-s} = \{t \mid S_t \subseteq R\}$$

I tested different structuring element sizes. A rectangular structuring element of size 50 × 80 removed the outer contour while causing minimal damage to the casting defect region. The result was a region that contained the plate tooth interior but not the outer boundary. For inner contour removal, I drew an ROI that covered the defect-free inner portions of the plate tooth. Since the part can shift, I moved this ROI using the affine matrix obtained from template matching. The inner contour removal step ensures that the two circular ring boundaries do not create false casting defect lines.

After removing the inner and outer contours, I extracted line contours from the remaining area. The line extraction algorithm is based on the second derivative of the image after Gaussian smoothing. It computes the direction of each line pixel and marks a pixel as a line point if the second derivative perpendicular to the line direction has a local maximum above a threshold. The low and high thresholds are computed from contrast, width, and sigma:

$$\begin{pmatrix} Low \\ High \end{pmatrix} = -2 \cdot \begin{pmatrix} ContrastLow \\ ContrastHigh \end{pmatrix} \cdot \frac{w}{\sqrt{2\pi}\sigma^3}\exp\left(-\frac{w^2}{2\sigma^2}\right)$$

Here, \(\sigma\) is the Gaussian smoothing parameter, \(w\) is the line width, and ContrastLow and ContrastHigh are the gray-level contrast values. I found that \(\sigma=2\) missed some faint casting defect lines, while a very small \(\sigma\) produced too many interference lines. I selected \(\sigma=1\), which extracted the casting defect lines while keeping interference at a manageable level.

Even after line extraction, many short interference lines remained. I first removed contours whose length was very small. I tested length thresholds from 5 to 8. A threshold in this range reduced interference without breaking the casting defect. If the threshold was too large, the casting defect could be removed or broken into pieces. If the threshold was too small, the interference lines could merge later and cause false positives. I therefore selected a small-contour removal threshold between 5 and 8 pixels.

After removing small contours, I performed line merging. The first merging operation uses four parameters: MaxDistAbs, MaxDistRel, MaxShift, and MaxAngle. MaxDistAbs is the maximum distance between the projection of a short line endpoint onto the reference regression line of a long line and the long line endpoint. MaxDistRel is the ratio of that projection distance to the length of the long line. MaxShift is the maximum perpendicular distance from the short line to the reference regression line. MaxAngle is the maximum angle difference between two lines. When these conditions are satisfied, the lines are merged. Because I had already removed very short interference lines, I could set MaxDistRel small enough to prevent most interference lines from merging. I then applied a second merging operation that only considers endpoint distance and angle. This second operation joined broken casting defect segments while avoiding most isolated interference. After merging, I extracted long lines using a length feature. I found that a length threshold of about 90 pixels selected the casting defect region reliably.

Parameter Purpose Effect if too small Effect if too large
Small contour length threshold Remove tiny interference Interference remains Casting defect may break
MaxDistAbs Control endpoint projection distance Fewer merges Incorrect merges
MaxDistRel Control relative endpoint distance Interference not merged Interference may merge
MaxShift Control perpendicular offset Fewer merges Wrong lines merge
MaxAngle Control angle difference Fewer merges Unrelated lines merge
Final line length Select casting defect False positives increase Casting defect missed

I applied this casting defect detection algorithm to many plate teeth. The method successfully extracted the casting defect as a long line while rejecting most texture interference. I tested 100 plate tooth images and obtained an accuracy of about 95%. I considered this a good initial result for an industrial prototype. The system is also capable of saving images that contain casting defects, which allows later human confirmation and algorithm improvement. The main test results are summarized below.

Test item Result Comment
Number of test images 100 Various plate teeth and positions
Detection accuracy 95% Initial laboratory result
Missed casting defect Not allowed Main safety requirement
False positive tolerance ≤ 0.1% Requires further optimization
Cycle time target ≤ 300 ms Met in tested configuration
Defect image storage Implemented Used for review

I implemented the software with Visual Studio and Halcon. Halcon provided the machine vision algorithms, including filtering, morphology, template matching, line extraction, and feature selection. Visual Studio with MFC provided the graphical user interface and system logic. I used C++ to connect the two environments. The software includes user permission management, camera control, parameter setting, automatic operation, image loading, and result display. The main interface allows an operator to load an image, run casting defect detection, and view the result. The software also records the total number of inspected parts, the number of defect-free parts, the number of defective parts, and the inspection time.

The user permission module prevents accidental parameter changes by operators. When the system starts, it automatically enters operator mode. If an operator tries to open the parameter setting page, the system denies access and displays a warning. An administrator can log in to modify parameters. The password is stored in a system file. When the password is changed, the system file is updated. This design prevents unauthorized changes that could affect casting defect detection reliability.

Software module Main functions Implementation detail
User permission Login, logout, password change Reads and writes an initialization file
Camera control Connect camera, set exposure, contrast, mirror, trigger Uses camera SDK and data stream buffer
Image processing Target extraction and casting defect detection Halcon procedures called from C++
Parameter setting Store and load algorithm parameters Uses GetPrivateProfileString and related functions
Automatic operation Continuous inspection thread Switch-case cycle for each image
Result display Show image, defect marks, and statistics MFC picture control and text controls

For the camera module, I first search for available cameras and connect to the selected device. I open the data stream and set the trigger mode. In automatic mode, the system waits for a hardware trigger. When an image is available, it is copied from the buffer, displayed, and sent to the image processing thread. The preprocessing, target extraction, and casting defect detection steps are then executed. If a casting defect is found, the result image is saved and a rejection signal is sent. If no casting defect is found, the system waits for the next trigger. I also provided a continuous acquisition mode for testing and a load-image mode for offline debugging.

The parameter setting module stores all important parameters. These include the erosion matrix size, the inner ROI circle centers and radii, the template matching score threshold, the line extraction parameters, the two line merging parameter sets, and the final line length threshold. Storing these parameters allows the system to be optimized without recompiling the software. I read parameters from an initialization file at startup and write them back when the administrator saves changes. This makes the software practical for industrial use.

From a theoretical perspective, the most important contribution of my work is the combination of shape-based target extraction and line-based casting defect detection. Shape-based matching solves the problem of locating a part whose surface texture varies. The affine ROI transformation solves the problem of inner contour removal under small part displacement. The line extraction and two-stage merging solve the problem of separating long casting defects from short texture interference. The median filter solves the problem of salt-and-pepper noise in the green channel. The morphological erosion solves the problem of outer contour interference. Together, these steps form a complete pipeline for casting defect detection.

In my experiments, I observed that the casting defect signal is sensitive to focus and illumination. If the focus is set purely for surface sharpness, the casting defect may be blurred. If the illumination is too uniform, the fluorescence contrast may be weak. If the illumination is too strong, reflections may create false lines. Therefore, I recommend that the system be installed with a fixed camera position, a fixed light source angle, and a repeatable part placement mechanism. The white background plate also helped stabilize segmentation when Blob analysis was used, although the final system uses template matching for target extraction. The magnetic particle and fluorescent illumination remain essential because they convert an invisible casting defect into a visible line-like indication.

I also considered the relationship between detection speed and robustness. A high pyramid level speeds up template matching but can reduce accuracy. A very small angle step increases accuracy but also increases computation time. A large line extraction sigma reduces noise but can remove faint casting defects. A small final line length threshold increases sensitivity but also increases false positives. I tuned these parameters experimentally. My general strategy was to first ensure that no casting defect is missed, then reduce false positives by removing short interference lines and by tightening the merging conditions. Since the production requirement allows a small number of false positives but no missed casting defects, this strategy is appropriate.

The following equations summarize the main mathematical operations in my casting defect detection system. The median filter is:

$$g_{r,c} = \mathrm{med}\{f_{k,l}\mid (k,l)\in W\}$$

The dynamic threshold condition for bright objects is:

$$S=\{(r,c)\in R \mid f_{r,c}-g_{r,c}\ge g_{\mathrm{diff}}\}$$

The SAD similarity measure is:

$$SAD_{r,c}=\frac{1}{n}\sum_{(u,v)\in T}|t_{u,v}-f_{r+u,c+v}|$$

The SSD similarity measure is:

$$SSD_{r,c}=\frac{1}{n}\sum_{(u,v)\in T}[t_{u,v}-f_{r+u,c+v}]^2$$

The normalized cross-correlation is:

$$NCC_{r,c}=\frac{1}{n}\sum_{(u,v)\in T}\frac{t_{r,c}-m_t}{s_t}\cdot\frac{f_{r+u,c+v}-m_{f,r,c}}{s_{f,r,c}}$$

The erosion operation is:

$$R\ominus S = \bigcap_{s\in S} R_{-s} = \{t \mid S_t \subseteq R\}$$

The affine transformation for ROI tracking is:

$$HomMat = \begin{pmatrix} \cos\theta & -\sin\theta & \Delta Row \\ \sin\theta & \cos\theta & \Delta Column \\ 0 & 0 & 1 \end{pmatrix}$$

The line extraction threshold relation is:

$$\begin{pmatrix} Low \\ High \end{pmatrix} = -2 \cdot \begin{pmatrix} ContrastLow \\ ContrastHigh \end{pmatrix} \cdot \frac{w}{\sqrt{2\pi}\sigma^3}\exp\left(-\frac{w^2}{2\sigma^2}\right)$$

These equations are the mathematical foundation of the casting defect detection pipeline. They are not independent; they work together to enhance the casting defect, locate the part, remove contours, extract lines, and select the final casting defect.

I also compared the performance of different stages in a qualitative table. The table below summarizes the role of each stage and its main risk.

Processing stage Main operation Benefit for casting defect detection Main risk
Channel selection Use green channel Improves casting defect contrast Other channels may contain useful information
Median filtering 1.5 × 1.5 rectangular mask Removes salt-and-pepper noise Large mask weakens casting defect
Template matching Shape-based matching with scaling Locates plate tooth robustly Requires good template
Outer contour removal Morphological erosion Removes long outer boundary Too large erosion removes defect
Inner contour removal Affine ROI Removes inner ring boundaries ROI must follow part position
Line extraction Second derivative line filter Enhances line-like casting defect Sigma selection is critical
Small contour removal Length filtering Reduces texture interference Too large threshold breaks defect
Line merging Two-stage merging Joins broken casting defect Wrong parameters merge interference
Final selection Length threshold Selects casting defect Threshold affects false positives

Regarding the overall system performance, I tested the software in the laboratory with a set of plate teeth. The system was able to inspect images and display the casting defect position. It also saved images of defective parts. The laboratory test did not cover all possible production conditions, but it demonstrated that the approach is feasible. The next step would be to perform a larger trial on the production line and collect more data on false positives and missed casting defects. I would also improve the inner and outer contour removal so that the casting defect is never removed. In addition, I would test the software for long-term stability and optimize the user interface for shop-floor operation.

I believe that machine vision for casting defect detection will continue to grow in importance. The demand for precision castings is increasing, and manual inspection cannot satisfy the requirements for consistency, speed, and safety. My system shows that a combination of magnetic particle enhancement, fluorescent illumination, industrial camera selection, template matching, and line-based casting defect extraction can provide a practical solution. The use of Halcon and Visual Studio makes the system flexible and maintainable. The parameter storage design allows engineers to adjust the system without recompiling the software. The user permission design prevents accidental changes. The defect image storage function supports continuous improvement.

In future work, I plan to improve the robustness of the casting defect detection algorithm under varying illumination. I also plan to test deep learning methods for casting defect classification, although the current line-based method is more interpretable and requires fewer training samples. I would like to combine the interpretable line-based method with a learned classifier so that the system can distinguish true casting defects from texture interference more reliably. I also plan to improve the mechanical positioning so that the template matching search range can be reduced, which would further decrease the cycle time. Finally, I plan to conduct a long-term factory trial and collect statistics on accuracy, false positive rate, missed detection rate, and mean time between failures.

The main conclusion of my work is that a visual system for casting defect detection can be developed by carefully combining hardware selection, image preprocessing, target extraction, and line-based defect extraction. My system meets the basic industrial requirements of automatic inspection, defect image storage, and user-friendly operation. The casting defect is made visible by magnetic particle and fluorescent methods, and the algorithm extracts it by removing contours, extracting lines, removing small interference, merging line segments, and selecting long lines. The system achieved about 95% accuracy on a laboratory test set of 100 images. Although further optimization is needed for full production deployment, the results show that the approach is promising and suitable for further development.

I summarize the key design choices in the final table below. This table represents my main engineering decisions and the reasons behind them.

Design choice Selected option Reason
Defect enhancement Magnetic particle with fluorescent illumination Makes casting defect visible
Camera type Color CCD, high resolution Green channel contrast and industrial stability
Trigger mode Hardware trigger Capture at correct part position
Preprocessing Green channel and median filter Reduce noise and preserve defect
Target extraction Shape-based template matching Robust to part variation and illumination
Outer contour removal Morphological erosion Remove long outer boundary
Inner contour removal Affine ROI tracking Remove inner ring boundaries
Defect extraction Line extraction, small contour removal, line merging Separate long casting defect from short texture
Software platform Visual Studio MFC with Halcon Rapid development and industrial vision algorithms
User management Operator and administrator modes Prevent accidental parameter changes

Overall, my project demonstrates that casting defect detection can be automated with a carefully designed visual system. The system reduces the need for direct human observation of fluorescent light, improves inspection consistency, stores evidence of casting defects, and provides a foundation for further optimization. I will continue to refine the algorithm and test it under real production conditions so that the system can eventually be deployed as a reliable tool for casting defect inspection.

Scroll to Top