I designed this work to solve a practical industrial problem: casting defects such as surface cracks, cold shuts, inclusions, pores, and hidden fissures are difficult to detect reliably by human eyes, especially when the defects are small or located near complex contours. In many production lines, fluorescent magnetic particle inspection is used to make casting defects visible. However, long-term direct viewing of fluorescent light can damage human eyes, and manual inspection is slow, subjective, and inconsistent. Therefore, I developed an automated machine vision system for casting surface defect detection. The system acquires images of cast plate teeth, extracts the target, removes interfering contours, detects line-shaped casting defects, saves defective images, and communicates a rejection signal to the production line.
1. Motivation and Industrial Requirements
The main motivation of my work is the need for reliable and fast detection of casting defects without exposing operators to harmful fluorescent illumination. The inspected parts are produced by casting and pressing processes. Casting defects usually appear near two circular regions of the part. Some casting defects are visually weak under ordinary light, but after magnetic particle adsorption and fluorescent excitation, the defective regions become brighter or more distinctive in the green channel. The production line requires an automated vision system that can inspect the part within a short cycle time and preserve evidence for later verification.
The industrial requirements are summarized in the following table.
| Requirement | Target Value | Reason |
|---|---|---|
| Detection cycle time | Less than or equal to 300 ms | Match production line speed |
| Defective image saving | Enabled | Allow later manual review and system improvement |
| Missed detection | Not allowed | Defective castings must not pass |
| False detection rate | Less than or equal to 0.001 | Reduce unnecessary rejection |
| Line integration | Required | Trigger camera and send rejection signal |
I express the timing and reliability constraints as follows:
$$T_{\mathrm{total}}=T_{\mathrm{acq}}+T_{\mathrm{pre}}+T_{\mathrm{match}}+T_{\mathrm{defect}}+T_{\mathrm{io}}\leq 300\,\mathrm{ms}$$
$$P_{\mathrm{miss}}=0,\qquad P_{\mathrm{false}}\leq 0.001$$
Here, \(T_{\mathrm{acq}}\) is image acquisition time, \(T_{\mathrm{pre}}\) is preprocessing time, \(T_{\mathrm{match}}\) is target extraction time, \(T_{\mathrm{defect}}\) is defect detection time, and \(T_{\mathrm{io}}\) is communication and image saving time. The requirement of zero missed casting defects strongly influences the design. I prefer a slightly higher false detection rate over any missed casting defects, because a missed casting defect can cause failure in later use.
2. Overall System Architecture
The system consists of three major parts: image acquisition, machine vision processing, and software interaction. The image acquisition part includes an industrial camera, a lens, a fluorescent light source, an industrial computer, and the existing mechanical handling device. The machine vision part extracts the target, removes internal and external contours, detects line-shaped casting defects, and marks their positions. The software part controls the camera, runs the detection algorithm, manages user permissions, saves parameters, logs production statistics, and stores defective images.
| Module | Function | Output |
|---|---|---|
| Image acquisition | Trigger camera, capture RGB image, display image | Raw image of casting surface |
| Preprocessing | Channel separation, denoising, contrast preparation | Clean green-channel image |
| Target extraction | Blob analysis or template matching to locate the casting | Region of interest and pose |
| Contour removal | Remove external and internal contours | Remaining inspection region |
| Defect detection | Line extraction, small-contour removal, line merging, feature selection | Detected casting defects |
| Decision and output | Save image, send rejection signal, update statistics | Pass or reject command |
The automatic flow I implemented is as follows. First, the system adjusts the light intensity, camera exposure, and lens focus. Second, a hardware trigger starts image acquisition when the part reaches the inspection position. Third, template matching checks whether a casting is present. If no casting is present, the camera buffer is cleared and the system waits for the next trigger. Fourth, the target is extracted. Fifth, the defect detection algorithm is applied. Sixth, if casting defects are found, the system marks the defective region, saves the image, and sends a rejection signal. If no casting defects are found, the system returns to the waiting state.
3. Hardware Selection and Imaging Setup
Hardware selection is critical because the quality of casting defect detection depends strongly on image quality. I considered resolution, sensor type, target size, color capability, trigger mode, lens matching, illumination geometry, and industrial computer performance.
| Hardware | Selected Property | Reason |
|---|---|---|
| Industrial camera | Color CCD camera, approximately 2058 by 2488 pixels | High resolution and stable imaging for small casting defects |
| Sensor | CCD | Low noise and good sensitivity |
| Trigger mode | Hardware trigger | Capture exactly when the part is in position |
| Lens | Manual zoom and focus lens | Adjustable for installation space and focus |
| Light source | Fluorescent source with side illumination | Excite magnetic particle indications of casting defects |
| Industrial computer | 64-bit system, 8 GB memory, i5 or higher | Support image processing and continuous operation |
For the camera, I selected a color CCD camera because the defect response after fluorescent excitation is more visible in the green channel. The camera resolution was chosen so that the physical size represented by one pixel is approximately 0.04 mm, which is sufficient for the expected casting defects. The target should occupy about two thirds of the field of view to balance resolution and processing speed. The camera is triggered by hardware rather than software, because hardware triggering is more deterministic on a moving production line.
For the lens, I used a manually adjustable lens instead of a telecentric lens. A telecentric lens can reduce distortion and provide stable magnification, but it is costly and not necessary for this application. The lens target size should match the camera sensor size to avoid dark corners or image loss. Because the installation space is limited, the lens must support focus and aperture adjustment.
For illumination, I used a fluorescent source with side illumination. The fluorescent light excites the magnetic particle indication on casting defects. The light source is not only an illumination component; it is part of the physical principle that makes casting defects visible. Without proper fluorescent excitation, many casting defects remain hidden. The image below represents a typical cast engine cylinder block, which helps illustrate the type of industrial casting surface that requires inspection.

The imaging setup includes a magnetic particle application station, a fluorescent excitation station, a camera, a lens, and an industrial computer. The part is transferred by a mechanical device, magnetized, sprayed with magnetic suspension, and then moved to the inspection position. The camera captures the casting surface under fluorescent illumination. Because the fluorescent light can injure human eyes, the automated vision system removes the need for continuous human observation.
I also tested different focus distances. The sharpness of the casting surface and the visibility of casting defects do not always peak at the same focus. A slightly defocused surface can make line-shaped casting defects more visible because the high-frequency surface texture is suppressed while the defect line remains continuous. The comparison is shown below.
| Focus Distance | Casting Surface Sharpness | Casting Defect Visibility | Decision |
|---|---|---|---|
| 0.50 cm | Very sharp | Poor | Not selected |
| 0.52 cm | Moderate | Moderate | Not selected |
| 0.54 cm | Slightly soft | Clearly visible | Selected |
I selected 0.54 cm because the goal is not to inspect the entire casting texture but to detect casting defects. A slightly softer casting surface reduces texture interference and improves the contrast of the defect lines.
4. Image Preprocessing
The raw image from the industrial camera is an RGB image. I split the image into red, green, and blue channels. After comparison, I found that casting defects under fluorescent illumination are more distinguishable in the green channel. Therefore, the green channel is used for subsequent processing. The green channel still contains noise, especially salt-and-pepper noise, so denoising is necessary before target extraction and defect detection.
Common noise types in this application include salt-and-pepper noise, Gaussian noise, Poisson noise, and multiplicative noise. I considered frequency-domain denoising, time-domain averaging, and spatial-domain filtering. Frequency-domain denoising is not suitable because the frequency components of casting defects are close to those of noise. Time-domain averaging requires multiple images of the same scene, which conflicts with the real-time requirement. Therefore, I used spatial-domain filtering.
The median filter is written as follows:
$$g_{r,c}=\operatorname{median}\{f_{k,l}\mid (k,l)\in W\}$$
The mean filter is written as follows:
$$g_{r,c}=\frac{1}{m}\sum_{(k,l)\in W}f_{k,l}$$
The Gaussian filter is written as follows:
$$G(x,y)=\frac{1}{2\pi\sigma^2}\exp\left(-\frac{x^2+y^2}{2\sigma^2}\right)$$
I compared different median filter templates. A circular template with radius 1 preserves casting defects well but leaves salt-and-pepper noise. A rectangular template of size 1.5 by 1.5 removes salt-and-pepper noise while preserving the line-shaped casting defects. Therefore, I selected a rectangular median filter with a 1.5 by 1.5 template.
| Filter Template | Noise Removal | Casting Defect Preservation | Decision |
|---|---|---|---|
| 1 by 1 rectangle | None | Excellent | Not selected |
| 1.5 by 1.5 rectangle | Good | Good | Selected |
| Circle radius 1 | Poor | Excellent | Not selected |
| Circle radius 1.5 | Moderate | Moderate | Not selected |
Preprocessing reduces noise but does not remove the need for robust target extraction. The casting surface still contains texture, reflections, and edge structures that can be confused with casting defects. Therefore, I designed the target extraction and defect detection stages carefully.
5. Target Extraction
The purpose of target extraction is to locate the casting in the image, obtain the region of interest, and provide pose information for later contour removal. I evaluated two approaches: Blob analysis and template matching. I implemented both and compared their stability, completeness, and suitability for casting surface defect detection.
5.1 Blob Analysis
Blob analysis segments an image into foreground and background, connects similar pixels into regions, and extracts features such as area, center, and bounding box. The basic threshold segmentation is defined as follows:
$$S=\{(r,c)\in R\mid g_{\min}\leq f_{r,c}\leq g_{\max}\}$$
For uneven illumination, dynamic threshold segmentation can be used. For bright objects, the dynamic threshold is:
$$S=\{(r,c)\in R\mid f_{r,c}-g_{r,c}\geq g_{\mathrm{diff}}\}$$
For dark objects, the dynamic threshold is:
$$S=\{(r,c)\in R\mid f_{r,c}-g_{r,c}\leq -g_{\mathrm{diff}}\}$$
Here, \(f_{r,c}\) is the original gray value, \(g_{r,c}\) is the smoothed local background value, and \(g_{\mathrm{diff}}\) is the threshold difference. The width of the smoothing filter must be larger than the object width; otherwise, the segmented region may be incomplete.
I first tried dynamic threshold segmentation with a large filter. The casting and a background pipe were connected, so the segmentation failed. After reducing the filter size, the casting could be segmented in some images, but the result was not universal. Changing the illumination or camera position changed the segmentation. To improve stability, I added a white background plate below the object. This changed the illumination toward a backlight-like condition and made the casting easier to separate. After region filling and area feature selection, the casting could be extracted.
| Blob Step | Operation | Issue |
|---|---|---|
| Segmentation | Fixed or dynamic threshold | Background and casting gray values overlap |
| Region filling | Fill holes | May connect unwanted background structures |
| Feature extraction | Area, bounding box, center | Edge is incomplete when illumination changes |
| Cropping | Extract casting region | Not always robust for different castings |
Blob analysis can extract the casting, but the extracted edge is often incomplete. The result depends on surface reflectivity and illumination. Since casting defects are line-shaped and may lie near the contour, an incomplete target edge can affect later processing. Therefore, Blob analysis is not the best choice for this system.
5.2 Template Matching
Template matching searches an image for the region most similar to a template. I considered gray-value matching, edge-based matching, and shape-based matching. Gray-value matching uses similarity measures such as SAD, SSD, and NCC.
$$SAD_{r,c}=\frac{1}{n}\sum_{(u,v)\in T}|t_{u,v}-f_{r+u,c+v}|$$
$$SSD_{r,c}=\frac{1}{n}\sum_{(u,v)\in T}[t_{u,v}-f_{r+u,c+v}]^2$$
$$NCC_{r,c}=\frac{1}{n}\sum_{(u,v)\in T}\frac{t_{u,v}-m_t}{\sqrt{s_t^2}}\cdot\frac{f_{r+u,c+v}-m_{f_{r,c}}}{\sqrt{s_{f_{r,c}}^2}}$$
NCC is more robust to linear illumination changes than SAD or SSD. However, gray-value matching is still sensitive to texture changes and local deformation. Edge-based matching depends heavily on edge extraction, and the edge of the casting is not always stable because of reflections and casting defects. Shape-based matching uses pixel direction vectors and is more robust to partial occlusion, nonlinear illumination change, and blurred edges. Therefore, I selected shape-based template matching with anisotropic scaling.
To accelerate the search, I used an image pyramid. Each higher pyramid level reduces the pixel count by a factor of four, which can increase the search speed by a factor of about sixteen per level.
| Pyramid Level | Pixel Reduction Factor | Search Speed Compared with Original |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 4 | 16 |
| 3 | 16 | 256 |
| 4 | 64 | 4096 |
| 5 | 256 | 65536 |
When creating the template, I set the pyramid level, starting angle, angle range, angle step, minimum and maximum scale, scale step, template optimization, polarity, and contrast. The template is selected from a region without casting defects. Since different castings have small shape variations, anisotropic scaling is enabled. The matching result returns the position, angle, scale, and score.
To extract the whole casting rather than only the template center, I use the following procedure. First, I record the template coordinates and angle when the template is created. Second, I define a region of interest that contains the entire casting. Third, for a new image, template matching returns the current coordinates and angle. Fourth, I compute an affine transformation matrix from the template pose to the current pose. Fifth, I transform the region of interest by this matrix. The transformed region is the extracted casting region.
The affine relation is:
$$\begin{pmatrix}R\\C\\1\end{pmatrix}=HomMat\begin{pmatrix}R_1\\C_1\\1\end{pmatrix}$$
The transformation matrix is:
$$HomMat=\begin{pmatrix}\cos\theta & -\sin\theta & \Delta R\\ \sin\theta & \cos\theta & \Delta C\\0&0&1\end{pmatrix}$$
where \(\theta=A_1-A\), \(\Delta R=R_1-R\), and \(\Delta C=C_1-C\). This matrix allows the region of interest to follow the casting even when the casting position or rotation changes.
At first, matching was unstable when different castings were tested. I analyzed the problem and found that different castings differ in small surface details. These details reduce the matching score. To solve this, I smoothed the image before matching so that only the main contour remained. This raised the matching score by about 0.1 and improved stability.
| Extraction Method | Completeness | Robustness to Illumination | Pose Information | Suitability |
|---|---|---|---|---|
| Blob analysis | Often incomplete at edges | Moderate | Limited | Not selected |
| Template matching | Complete region through ROI transform | Good after smoothing | Position, angle, scale | Selected |
After comparing the two methods, I selected template matching. It provides a more complete casting region and supplies pose information for later contour removal. This is important because casting defects near internal or external contours can be confused with the contours themselves.
6. Removal of Internal and External Contours
The casting has strong external and internal contours. These contours have gray values and shapes similar to line-shaped casting defects, so they must be removed before defect detection. I remove the external contour by morphological erosion and the internal contour by a tracked region of interest.
Morphological erosion of a region is defined as:
$$R\ominus S=\{t\mid S_t\subseteq R\}$$
It can also be written as:
$$R\ominus S=\bigcap_{s\in S}R_{-s}$$
The structuring element \(S\) moves over the region. If \(S\) is completely contained in \(R\), the point remains; otherwise, it is removed. By choosing an appropriate structuring element, the outer boundary of the casting is removed. I found that a rectangular structuring element of size 50 by 80 gives a good balance: it removes the external contour while preserving most casting defects.
| Parameter | Value or Strategy | Effect |
|---|---|---|
| External contour removal | Morphological erosion with 50 by 80 rectangle | Removes outer boundary |
| Internal contour removal | Tracked ROI using template pose | Removes known non-defect internal regions |
| ROI tracking | Affine matrix from template matching | ROI follows the casting |
For the internal contour, I draw a region of interest that covers the non-defect internal regions. This region is a union of two circular regions and one rectangular region. Because the casting position can change, the ROI must move with the casting. I use the same affine transformation matrix from template matching to move the ROI. The internal contour is then removed from the inspection image.
After external and internal contour removal, the remaining image contains the areas where casting defects are expected. However, the remaining image still contains interference points. Simple mean, median, Gaussian filtering, opening, or closing can remove interference but may also damage casting defects. Therefore, I designed a line-oriented interference removal method.
7. Line-Oriented Casting Defect Detection
The casting defects in this application are mainly line-shaped cracks formed during pressing and casting. Therefore, I detect casting defects by extracting line structures, removing small interference contours, merging line segments, and selecting long features. The overall algorithm is:
$$I_{\mathrm{defect}}=F_{\mathrm{feature}}\left(M_{\mathrm{merge}}\left(R_{\mathrm{small}}\left(L_{\mathrm{line}}\left(I_{\mathrm{roi}}\right)\right)\right)\right)$$
where \(I_{\mathrm{roi}}\) is the image after contour removal, \(L_{\mathrm{line}}\) is line extraction, \(R_{\mathrm{small}}\) removes small contours, \(M_{\mathrm{merge}}\) merges line segments, and \(F_{\mathrm{feature}}\) selects the final casting defects.
7.1 Line Extraction
The line extraction algorithm uses the local Hessian matrix. For each pixel, the second-order derivatives are computed:
$$H(x,y)=\begin{pmatrix}L_{xx}&L_{xy}\\L_{xy}&L_{yy}\end{pmatrix}$$
A point is considered a line point if the eigenvalue perpendicular to the line direction has a local maximum and the magnitude exceeds a threshold. The parameters include the Gaussian smoothing sigma, low hysteresis threshold, and high hysteresis threshold. The relationship is:
$$\begin{pmatrix}Low\\High\end{pmatrix}=-2\begin{pmatrix}C_{\mathrm{low}}\\C_{\mathrm{high}}\end{pmatrix}\frac{w}{\sqrt{2\pi}\sigma^3}\exp\left(-\frac{w^2}{2\sigma^2}\right)$$
Here, \(w\) is the line width, \(\sigma\) is the Gaussian smoothing parameter, and \(C_{\mathrm{low}}\) and \(C_{\mathrm{high}}\) are contrast values. If the second derivative is above High, the point is accepted as a line point. If it is below Low, it is rejected. If it lies between Low and High, it is accepted only if it can be connected to an already accepted line point.
I tested different sigma values. A large sigma value can miss weak casting defects. A small sigma value produces many interference lines, which can merge with each other and cause false detection. I found that sigma equal to 1 gives a good balance: it extracts the casting defect lines while keeping interference relatively low.
| Sigma Value | Casting Defect Extraction | Interference Level | Decision |
|---|---|---|---|
| 2 | Weak defects missed | Low | Not selected |
| 1 | Defect lines extracted | Manageable | Selected |
| Less than 1 | Many false lines | High | Not selected |
7.2 Removal of Small Interference Contours
After line extraction, the image contains many short interference contours. If these contours are merged directly, they may form false long lines and cause false detection of casting defects. Therefore, I first remove contours whose length is too small. The length of a contour is computed as:
$$L_i=\sum_{j=1}^{N_i-1}\sqrt{(x_{j+1}-x_j)^2+(y_{j+1}-y_j)^2}$$
I keep contours with length greater than a small threshold. I tested thresholds from 5 to 8. If the threshold is too large, the casting defect line may be broken or removed. If the threshold is too small, interference lines remain. A threshold between 5 and 8 works well for this application.
| Small Contour Threshold | Interference Reduction | Casting Defect Preservation | Decision |
|---|---|---|---|
| Less than 5 | Low | High | Not selected |
| 5 to 8 | High | High | Selected |
| Greater than 8 | Very high | Risk of missing defects | Not selected |
This step is important because it removes the small interference contours without destroying the line-shaped casting defects. It prepares the image for line merging.
7.3 Line Merging
Casting defect lines may be broken into several segments. At the same time, interference lines may also be present. I use two merging strategies. The first strategy uses four parameters: maximum absolute distance, maximum relative distance, maximum shift, and maximum angle difference.
| Parameter | Meaning | Role in Casting Defect Detection |
|---|---|---|
| MaxDistAbs | Maximum absolute distance between endpoints in the reference regression direction | Limits how far two segments can be apart |
| MaxDistRel | Maximum relative distance compared with the length of the longer segment | Prevents short interference segments from merging |
| MaxShift | Maximum perpendicular distance to the reference regression line | Ensures segments are nearly collinear |
| MaxAngle | Maximum angle difference between two segments | Ensures direction consistency |
The corresponding conditions are:
$$a\leq D_{\mathrm{abs}}$$
$$\frac{a}{b}\leq D_{\mathrm{rel}}$$
$$a\leq S_{\mathrm{max}}$$
$$\alpha\leq A_{\mathrm{max}}$$
If all conditions are satisfied, the two line segments are merged. Because small interference contours have already been removed, the relative distance condition prevents most interference segments from merging. The casting defect segments, which are longer and more collinear, can still merge.
The second merging strategy checks only the endpoint distance and the angle to the reference line. This is useful when a casting defect line has a small break in the middle. I set the endpoint distance threshold close to the small-contour removal threshold. This allows broken casting defect segments to connect while preventing interference segments from connecting. The endpoint distance is:
$$d(p_i,p_j)=\sqrt{(x_i-x_j)^2+(y_i-y_j)^2}\leq d_{\mathrm{merge}}$$
After the two merging stages, the interference lines are mostly separate, while the casting defect lines form longer connected structures. Then I extract features from the merged lines. The main feature is length. If a merged line is longer than a threshold, it is classified as a casting defect. In my tests, a final length threshold of 90 gives reliable extraction of the casting defects.
$$L_{\mathrm{defect}}\geq L_{\mathrm{threshold}}=90$$
| Final Length Threshold | False Detection | Missed Casting Defects | Decision |
|---|---|---|---|
| Below 90 | Higher | Lower | Not selected |
| 90 | Low | Low | Selected |
| Above 90 | Lower | Higher | Not selected |
The detected casting defects are marked on the image. If the length of a merged line exceeds the threshold, the system marks the corresponding region, saves the image, and sends a rejection signal. If no line exceeds the threshold, the casting is considered acceptable.
8. Software Implementation
I implemented the software using an integrated development environment with MFC and a machine vision library. The software includes user permission management, camera control, parameter setting, image loading, automatic operation, defect marking, result statistics, and defective image saving. The main interface displays the current image, the detection result, the total number of inspected parts, the number of accepted parts, the number of defective parts, and the elapsed time.
| Software Module | Main Function | Implementation Detail |
|---|---|---|
| User permission | Restrict access to parameter changes | Operator and administrator modes with password file |
| Camera module | Connect, configure, acquire, and display images | Camera SDK, buffer clearing, hardware trigger |
| Parameter module | Set and save detection parameters | INI file read and write through profile functions |
| Image processing module | Run target extraction and casting defect detection | Machine vision library functions called from C++ |
| Automatic mode | Run continuous inspection | Separate thread and state machine |
| Result module | Save defective images and update statistics | File storage and counter update |
The user permission module prevents operators from accidentally changing critical parameters. When the software starts, it checks whether a system file exists. If not, it creates the file and initializes the passwords. When an operator tries to open the parameter page, the system checks the current permission. If the user is not an administrator, access is denied and a prompt is displayed. The administrator can change the operator password and the administrator password.
The camera module connects to the camera through the camera SDK. It detects available cameras, closes previous connections, opens the data stream, clears the buffer, and waits for an image. When an image is available, it is transferred to the image processing module and displayed in the picture control. The camera exposure, contrast, mirror mode, and trigger mode can be configured. For debugging, the user can load an image from the computer and run defect detection without the camera.
The parameter setting module stores parameters such as erosion matrix size, internal ROI circle centers and radii, matching score threshold, line extraction parameters, line merging parameters, and final feature threshold. The parameters are stored in an INI file. I used profile read and write functions to load and save parameters. This makes it possible to tune the system without recompiling the software.
The automatic mode is implemented with a separate thread. When the camera captures an image, the software first checks whether a casting is present through template matching. If a casting is present, it runs the defect detection algorithm. If casting defects are found, it saves the image and sends a rejection signal. The state machine then returns to the waiting state. This design allows the software to run continuously on the production line.
9. Experimental Results and Discussion
I tested the system in the laboratory using different castings and different illumination conditions. The detection algorithm was applied to 100 casting images. The overall accuracy was 95 percent. The system successfully extracted line-shaped casting defects in most cases. The main sources of error were strong surface texture, incomplete contour removal, and interference lines that remained after small-contour removal.
$$A=\frac{N_{\mathrm{correct}}}{N_{\mathrm{total}}}\times 100\%=95\%$$
| Test Item | Result | Observation |
|---|---|---|
| Number of images | 100 | Different castings and positions |
| Correct detection | 95 | Line-shaped casting defects extracted |
| Accuracy | 95% | Acceptable for initial system validation |
| Main error source | Surface texture and contour residue | Requires further optimization |
| Image saving | Successful | Defective images stored for review |
The system meets the basic requirement of automatic casting surface defect detection. It can detect casting defects, mark their positions, save defective images, and send rejection information. Compared with manual inspection, the system avoids direct exposure to fluorescent light and provides more consistent operation. However, I also observed limitations. The external contour removal by erosion may remove weak casting defects near the boundary. The internal ROI depends on accurate template matching. If the casting pose is incorrectly estimated, the ROI may not cover the correct region. The line merging parameters also require tuning for different casting types.
10. Future Improvements
I plan to improve the system in several directions. First, I will collect more casting images under different illumination, focus, and part conditions to evaluate the stability of casting defect detection. Second, I will design a more accurate method for internal and external contour removal so that weak casting defects near the boundary are not removed. Third, I will test the software on the production line for a long period to find software defects and improve robustness. Fourth, I will investigate adaptive parameter selection so that the system can handle different casting types without extensive manual tuning. Fifth, I will explore deep learning methods for casting defect classification, while keeping the line-based algorithm as a fast pre-screening method.
| Future Work | Expected Benefit | Challenge |
|---|---|---|
| More image data | Better statistical validation | Data labeling cost |
| Improved contour removal | Reduce missed casting defects near edges | Defect and contour similarity |
| Long-term line testing | Improve software reliability | Industrial environment variation |
| Adaptive parameters | Reduce manual tuning | Part-to-part variation |
| Deep learning classification | Improve defect recognition | Need large labeled dataset |
11. Conclusion
I developed a machine vision system for casting surface defect detection. The system uses fluorescent magnetic particle indication to make casting defects visible, a color CCD camera to capture images, and a machine vision algorithm to detect line-shaped casting defects. I designed the hardware configuration, selected the camera, lens, light source, and industrial computer, and built the image acquisition setup. I compared Blob analysis and template matching for target extraction and selected shape-based template matching with anisotropic scaling because it provides a complete casting region and pose information. I removed external contours by morphological erosion and internal contours by a tracked region of interest. I extracted line structures, removed small interference contours, merged line segments with controlled parameters, and selected long features as casting defects. I implemented the software with camera control, user permission management, parameter storage, automatic operation, image saving, and result statistics. Laboratory tests on 100 casting images gave an accuracy of 95 percent. The system reduces the need for human exposure to fluorescent light, improves inspection consistency, and provides a practical foundation for automatic casting defect detection on a production line.
In my view, the most important contribution of this work is not a single algorithm but the integration of illumination, hardware, target extraction, contour removal, line extraction, interference suppression, and software control into a complete casting surface defect detection system. Casting defects are difficult because they are often similar to surface texture and contour structures. By combining fluorescent indication with a line-oriented vision algorithm, I was able to detect casting defects that are hard to identify by direct human observation. The system can be further optimized and extended to other casting types and other line-shaped surface defects.
