A method for automatically calibrating camera parameters for glass bottle inspection
Patent Information
- Application Number
- CN202611037251.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-13
- Publication Date
- 2026-10-09
AI Technical Summary
[0004]为解决现有技术中玻璃瓶检测相机参数依赖人工调试、曝光增益与色调修正缺乏联动、缺陷显现不稳定的技术问题,本发明提出了一种玻璃瓶检测相机参数自动校准方法
[0021]本发明将待测玻璃瓶的背光基准图像与结构光偏折图像拼接作为输入,通过双分支网络分别预测光度参数和分段三次埃尔米特插值曲线参数,并利用注意力机制融合生成最终曝光时间与模拟增益,实现相机采集参数和灰度映射参数的联合调节。
Smart Images

Figure CN122882470A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial vision intelligence technology. More specifically, this invention relates to an automatic calibration method for the parameters of a glass bottle detection camera. Background Technology
[0002] Glass bottles are commonly used packaging containers in the food and pharmaceutical industries, and their finished product quality directly affects product safety, storage and transportation reliability, and corporate reputation. During the production and handling of glass bottles, factors such as fluctuations in the melting and molding process, changes in mold condition, thermal stress release, and mechanical collisions can easily cause defects such as cracks, bubbles, stones, and scratches on the bottle body, bottom, or mouth. Due to the optical properties of glass, such as transparency, strong reflectivity, and complex refraction paths, ordinary visual imaging methods often struggle to reliably display minute defects or low-contrast defects, easily resulting in blurred defect boundaries, uneven background brightness, and localized highlight obstruction. In actual industrial inspection, multiple imaging methods, such as backlighting and structured light deflection, are typically combined to enhance the visibility of internal defects and surface morphology anomalies. Therefore, the exposure time, analog gain, and subsequent grayscale tone mapping parameters of the front-end inspection camera directly affect the defect clarity, background uniformity, and signal-to-noise ratio of the acquired image, and are crucial factors for the stable operation of a glass bottle visual inspection system.
[0003] Current methods for calibrating camera parameters in glass bottle inspection largely rely on manual experience or traditional global automatic exposure algorithms. Due to significant differences in transmission, reflection, and refraction responses among different batches, shapes, and thicknesses of glass bottles, fixed parameter templates struggle to adapt to continuous production environment changes. This can easily lead to localized overexposure that masks defects in highly reflective areas, or underexposure that obscures subtle defects by background noise. Furthermore, existing methods typically treat exposure, gain adjustment, and image tone enhancement as independent processes, lacking a joint optimization mechanism for defect identification effectiveness and failing to provide effective feedback based on defect visibility and background uniformity. Therefore, there is an urgent need for an automatic calibration method that can integrate multi-illumination image features and jointly optimize camera acquisition parameters and image tone correction parameters to improve the defect visibility of glass bottles and the adaptability of the inspection system. Summary of the Invention
[0004] To address the technical problems in existing glass bottle inspection cameras that rely on manual adjustment of parameters, lack linkage between exposure gain and tone correction, and exhibit unstable defect display, this invention proposes an automatic calibration method for glass bottle inspection camera parameters.
[0005] This invention provides an automatic calibration method for camera parameters in glass bottle inspection, comprising: S1, acquiring a backlight reference image and a structured light deflection image of the glass bottle to be tested, and stitching them along the channel dimension to form an input tensor; inputting the input tensor into a parameter prediction model, and outputting the initial exposure time and initial simulation gain through the photometric prediction branch; outputting the control point coordinates and first derivative of a piecewise cubic Hermitian interpolation curve with monotonically increasing grayscale channels through the tone prediction branch; S2, analyzing the control point coordinates and first derivative to form a tone correction vector; inputting the initial exposure time, initial simulation gain, and tone correction vector into a parameter fusion module, and adjusting and generating the final exposure time and... The final simulated gain is output, along with the final exposure time, final simulated gain, and piecewise cubic Hermitian interpolation curve, used to control camera acquisition and image processing. S3: During parameter prediction model training, the final exposure time and final simulated gain are converted into relative photometric adjustment coefficients using a differentiable photometric rendering engine. Combined with the piecewise cubic Hermitian interpolation curve, a differentiable photometric transformation is performed on the backlight reference image to generate a calibration image. A pre-trained segmentation network is used to obtain the defect probability map of the calibration image. Based on the defect probability map, the local contrast variance and luminance information entropy are calculated. The reciprocal of the local contrast variance and the luminance information entropy are weighted and summed to form the total loss. Backpropagation is then used to optimize the parameter prediction model.
[0006] This invention achieves automatic adjustment of camera acquisition hardware parameters and nonlinear grayscale mapping parameters, and utilizes defect probability guidance during model training. This effectively enhances the prominence of texture jumps in suspected defect areas, while improving the illumination uniformity of defect-free background areas. It also improves the local contrast and signal-to-noise performance of the detected image, significantly reducing the risk of false detection and false negative detection of defects.
[0007] Preferably, the step of acquiring the backlight reference image and the structured light deflection image of the glass bottle under test, and stitching them along the channel dimension to form an input tensor, includes: acquiring a transmission image of the glass bottle and extracting a grayscale matrix to generate a single-channel backlight reference image; acquiring three-dimensional reconstructed deflection information and converting it into a single-channel structured light deflection image; applying a scale normalization function to adjust and align the resolution of the backlight reference image and the structured light deflection image to a preset square resolution; and stitching the adjusted backlight reference image as the first channel and the adjusted structured light deflection image as the second channel side-by-side to generate a three-dimensional matrix as the input tensor.
[0008] This invention constructs complementary multimodal photometric features by spatially aligning and channel-splitting a backlit image reflecting the internal transmission undulations of a glass bottle with a structured light deflection image reflecting the microscopic morphological undulations of the surface, thus ensuring the integrity of the photometric information dimension input to the neural network.
[0009] Preferably, the step of outputting the initial exposure time and initial simulated gain through the photometric prediction branch includes: inputting the input tensor into a multi-layer convolutional downsampling network to extract deep image features and output a feature map; performing a global average pooling operation on the feature map to extract a multi-channel one-dimensional feature vector; inputting the one-dimensional feature vector into a fully connected layer and outputting a parameter vector containing two positive values through a non-linear activation function; separating the parameter vector, mapping the first value to the initial exposure time, and mapping the second value to the initial simulated gain.
[0010] Preferably, the step of constructing the control point coordinates and first derivative of a piecewise cubic Hermitian interpolation curve with monotonically increasing grayscale channels through the output of the hue prediction branch includes: uniformly presetting a fixed horizontal coordinate within the grayscale value range; extracting a non-negative vertical coordinate offset from the fully connected network branch output of the corresponding grayscale channel from the deep image features extracted by the parameter prediction model; accumulating the non-negative vertical coordinate offset and constructing the control point coordinates in combination with the fixed horizontal coordinate; and calculating the first derivative based on the secant slope constraint between adjacent control points.
[0011] This invention strictly guarantees the monotonically increasing characteristic of the generated grayscale mapping curve by outputting a non-negative vertical coordinate offset and performing cumulative constraints, preventing abnormal phenomena such as color level inversion and black-and-white inversion in the rendered image; combined with slope truncation processing, it effectively reduces artifacts and ringing overshoot caused by traditional interpolation at high-contrast edges.
[0012] Preferably, the step of analyzing the control point coordinates and the first derivative to form a tone correction vector includes: calculating the difference in ordinates between adjacent control points in the grayscale channel; calculating the change in the first derivative between adjacent control points in the grayscale channel; and concatenating all the differences in ordinates with the change in the first derivative to generate a one-dimensional continuous feature vector as the tone correction vector.
[0013] This invention accurately captures the differences in local luminance distribution and migration gradient distribution in nonlinear grayscale transformation by calculating and concatenating the difference in the ordinates of control points and the change in the first derivative, providing accurate and continuous prior luminance features for subsequent joint parameter tuning.
[0014] Preferably, the module for fusing the initial exposure time, the initial simulated gain, and the tone correction vector input parameters, and adjusting and generating the final exposure time and the final simulated gain through an attention mechanism, includes: concatenating the initial exposure time, the initial simulated gain, and the tone correction vector to form a fused feature vector; inputting the fused feature vector into a multilayer perceptron network, and outputting a weight coefficient vector through a hyperbolic tangent activation function; multiplying the elements of the weight coefficient vector by the initial exposure time and the initial simulated gain respectively to calculate the compensation increment; and superimposing the compensation increment onto the corresponding initial parameters and performing amplitude limiting processing to obtain the final exposure time and the final simulated gain.
[0015] Preferably, the step of calculating the local contrast variance and luminance information entropy based on the defect probability map includes: using the defect probability value in the defect probability map as a continuous high probability weight, and using the value obtained by subtracting the defect probability value from 1 as a continuous low probability weight; performing a weighted average of the gray values of each pixel in the calibration image based on the continuous high probability weight and calculating the weighted squared deviation to obtain the local contrast variance; and performing weighted statistics on the gray distribution of each pixel in the calibration image based on the continuous low probability weight to obtain the luminance information entropy.
[0016] Preferably, the step of acquiring the glass bottle transmission image and extracting the grayscale matrix to generate the single-channel backlight reference image includes: using a camera to photograph the glass bottle under backlight illumination to acquire the backlight reference image; the step of acquiring the three-dimensional reconstructed deflection information and converting it into the single-channel structured light deflection image includes: using a stripe projector to project phase-shifted stripes and simultaneously photographing to acquire the structured light deflection image.
[0017] Preferably, the step of converting the final exposure time and the final analog gain into a relative photometric adjustment coefficient includes: obtaining a reference exposure time and a reference analog gain; determining the ratio of the final exposure time to the reference exposure time as a relative exposure ratio; converting the change in the final analog gain relative to the reference analog gain into a relative linear gain ratio; and multiplying the relative exposure ratio by the relative linear gain ratio to obtain the relative photometric adjustment coefficient.
[0018] Preferably, the step of obtaining the luminance information entropy by weighting the grayscale distribution of each pixel in the calibration image based on the continuous low probability weights includes: continuously allocating the pixel grayscale values to multiple grayscale intervals using a soft histogram weighted statistical method, and calculating the probability value corresponding to each grayscale interval; substituting the probability value into the Shannon information entropy calculation formula with base 2, adding a small bias term to the logarithmic term, and then accumulating the terms one by one to obtain the luminance information entropy.
[0019] This invention effectively prevents the logarithmic function from generating infinite gradients or meaningless values when the input probability is 0 by introducing a small bias term into the logarithmic term of the Shannon information entropy, thus ensuring the numerical stability of the network's backpropagation and gradient update process.
[0020] The beneficial effects of this invention are as follows:
[0021] This invention uses a backlit reference image of the glass bottle under test and a structured light deflection image as input. It predicts photometric parameters and piecewise cubic Hermite interpolation curve parameters through a dual-branch network, and uses an attention mechanism to fuse and generate the final exposure time and simulated gain, thereby achieving joint adjustment of camera acquisition parameters and grayscale mapping parameters.
[0022] Furthermore, during the model training phase, a calibration image is generated using a differential photometric rendering engine, and the defect probability distribution is obtained through a pre-trained segmentation network. Then, a defect identification loss is constructed by combining local contrast variance and luminance entropy, guiding the model to enhance the texture salience of suspected defect areas and improve the uniformity of background areas. This improves the local contrast and signal-to-noise ratio of the detected image, reduces the risk of false positives and false negatives caused by mismatched imaging parameters, and enhances the adaptability and reliability of glass bottle defect detection. Attached Figure Description
[0023] Figure 1 This is a flowchart of an automatic calibration method for camera parameters for glass bottle detection according to the present invention; Figure 2 This is a schematic diagram of the one-dimensional grayscale distribution curves of the backlight reference image and the structured light deflection image in this invention; Figure 3 This is a schematic diagram of the feature value distribution of each dimension of the 14-dimensional tone correction vector in this invention; Figure 4 This is a schematic diagram showing a quantitative comparison of three evaluation indicators between the control group algorithm and the experimental group algorithm in this invention. Detailed Implementation
[0024] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments.
[0025] This invention discloses an automatic calibration method for camera parameters in glass bottle detection, referring to... Figure 1 This includes steps S1-S3: S1. Obtain the input tensor and predict the initial luminance and hue parameters.
[0026] In an optional embodiment, a backlit reference image and a structured light deflection image of the glass bottle to be tested are acquired and stitched together along the channel dimension to form an input tensor; the input tensor is input into a parameter prediction model, and the initial exposure time and initial simulation gain are output through the photometric prediction branch; the control point coordinates and first derivative of a piecewise cubic Hermitian interpolation curve with monotonically increasing grayscale channels are output through the hue prediction branch.
[0027] An industrial camera was used to photograph a glass bottle under backlighting to obtain a backlit reference image. A stripe projector was used to project phase-shifted stripes, and a structured light deflection image was simultaneously captured by the industrial camera. Both the backlit reference image and the structured light deflection image were read separately, and their sizes were adjusted to the same resolution, for example, 512×512 pixels. The single-channel backlit reference image and the single-channel structured light deflection image were merged according to their channel directions to form a three-dimensional data matrix containing two image channels. Subsequently, the three-dimensional data matrix was converted into a tensor format recognizable by the deep learning framework, and the pixel grayscale values were normalized to map the pixel grayscale values to the range of 0 to 1, resulting in an input tensor of size 2×512×512. It should be noted that adjusting the image size to 512×512 pixels was achieved through calibration experiments testing the receptive field coverage and computation time of the deep learning model at different resolutions, ensuring that computational efficiency is considered while meeting the requirements for defect feature extraction accuracy.
[0028] The parameter prediction model is constructed using a convolutional neural network based on the ResNet50 architecture. The number of input channels in the first convolutional layer is adjusted to 2 to accommodate the input tensor consisting of the backlight reference image channel and the structured light deflection image channel. The input tensor passes through multiple 2D convolutional layers, batch normalization layers, and activation functions to extract global feature maps. These global feature maps are then fed into the photometric prediction branch and the tone prediction branch, respectively. In the photometric prediction branch, an average pooling layer is used to reduce the dimensionality of the feature map. Two fully connected layers and a sigmoid activation function output two scalar values between 0 and 1, which are mapped to the allowable exposure time range and gain range of the industrial camera, respectively, to obtain the preliminary exposure time and preliminary simulated gain. In the tone prediction branch, the global feature map passes through a similar multilayer perceptron structure. The last layer outputs a set number of N non-negative ordinate offsets. The x-coordinates of the control points are pre-fixed within the grayscale value range, and the ordinates of the control points are determined based on the accumulated results of the non-negative ordinate offsets. Then, the first derivative at each control point is calculated based on the secant slope constraint between adjacent control points. This method ensures that the grayscale mapping curve is monotonically increasing and that the output control point coordinates and first derivatives meet the monotonicity requirements of the piecewise cubic Hermitian interpolation algorithm. It should be noted that the preset number of control points N to 8 was obtained through nonlinear grayscale mapping experiments on a large number of glass bottle sample images under different lighting conditions. This allows for accurate capture of local contrast variation features while maintaining the smoothness of the interpolation curve.
[0029] In an optional embodiment, a backlit reference image and a structured light deflection image of the glass bottle under test are acquired and stitched together along the channel dimension to form an input tensor. Specifically, a transmission image of the glass bottle is acquired through a backlit camera module, and a grayscale matrix is extracted to generate a single-channel backlit reference image; the 3D reconstruction deflection information under structured light illumination is acquired and converted into a single-channel structured light deflection image; a scale normalization function is applied to adjust and align the resolution of the backlit reference image and the structured light deflection image to a preset square resolution; the adjusted backlit reference image is used as the first channel and the adjusted structured light deflection image is used as the second channel, and they are stitched together in parallel to generate a 3D matrix with a preset square resolution and two channels, and this 3D matrix is used as the input tensor.
[0030] During the hardware acquisition phase, the backlight camera module preferably uses a 20-megapixel global shutter complementary metal-oxide-semiconductor monochrome industrial camera with a target surface size of 1 inch, paired with a blue light-emitting diode surface light source with a center wavelength of 460nm for backlight illumination, acquiring an original transmission image with an 8-bit grayscale depth. The grayscale matrix of a single channel in the original transmission image is extracted to construct a backlight reference image with a size of 5472×3648. Sinusoidal fringe structured light is projected onto the surface of the glass bottle using an LCD screen. The phase information and normal vector of the glass bottle surface are calculated using the phase-shifting method. The angular deflection information of the normal vector is normalized and mapped to a grayscale range of 0 to 255, generating a single-channel structured light deflection image with the same bit depth.
[0031] Reference Figure 2 The backlight reference image signal exhibits a smooth, undulating distribution with a central convexity and gently sloping sides, while the structured light deflection image signal displays a sinusoidal wave distribution with equal amplitude and periodicity. The smooth distribution of the backlight reference image signal reflects the gradual change in transmitted light intensity inside the glass bottle, effectively characterizing the transparency and impurity obstruction of the internal material. The periodic fluctuations of the structured light deflection image signal reflect the phase modulation of the projected fringes on the glass bottle surface, accurately characterizing the undulations of the surface microstructure. This demonstrates that by combining backlight transmission information and structured light deflection information, complementary multimodal photometric features can be constructed, ensuring the integrity of the dimensions of the input photometric information.
[0032] Bilinear interpolation or Lanczos resampling is used as the scale normalization function to uniformly scale and crop two images with different original field-of-view ratios to a preset square resolution. To adapt to the receptive field and computational efficiency of conventional deep learning backbone networks, the preset square resolution is preferably set to 512×512 pixels or 1024×1024 pixels. In the depth tensor construction step, channel concatenation operations, such as the tensor merging function, are used to assign channel index 0 as the first channel to the resolution-aligned backlit reference image and channel index 1 as the second channel to the structured light deflection image, generating a 2×512×512 three-dimensional tensor matrix. This results in an input tensor with spatial alignment, which is then fed into the deep convolutional network for feature extraction.
[0033] In an optional embodiment, the input tensor is used to input the parameter prediction model, and the initial exposure time and initial simulated gain are output through the photometric prediction branch. Specifically, the input tensor is input into a multi-layer convolutional downsampling network to extract deep image features and output a feature map; global average pooling is performed on the feature map to compress the spatial dimension and extract a one-dimensional feature vector for multiple channels; the one-dimensional feature vector is input into a fully connected layer, and a parameter vector containing two positive values is output through a non-linear activation function; the parameter vector is separated, and the first value is used as the initial exposure time, and the second value is used as the initial simulated gain.
[0034] Multi-layer convolutional downsampling networks preferably use residual networks or efficient networks with the top fully connected layers removed as the backbone architecture. The input of the backbone network is the input tensor, denoted as . Based on the standard tensor dimension of convolutional neural networks, the spatial dimension of the input tensor is constructed as follows:
[0035] in, The spatial dimension of the input tensor; The number of channels in the input tensor; Input the height of the tensor; This is the width of the input tensor; it should be noted that in this embodiment, It is 2. and Both are 512.
[0036] Five spatial downsampling feature extraction operations are performed sequentially through multiple convolutional layers with a stride of 2. Each feature extraction layer sequentially performs convolution operations, batch normalization, and nonlinear activation. Specifically, the feature map output from the previous layer is first processed by the convolutional kernel of the current layer for local feature extraction to obtain the convolutional response result. Then, the convolutional response result is batch normalized to stabilize the numerical distribution of features from different channels. Finally, a nonlinear expressive capability is introduced through a linear rectified activation function or a leaky linear rectified activation function to obtain the feature map output from the current layer. After five downsampling operations with a stride of 2, the spatial size of the input image is gradually reduced from 512×512 to 16×16, while the number of channels is expanded to 512, forming a deep image feature map with a size of 512×16×16. By performing a global average pooling operation on the spatial dimension of the feature map, the average value of 256 pixels in each channel is taken to reduce spatial location dependence, and the feature map is aggregated into a 512-dimensional multi-channel one-dimensional feature vector to represent the abstract features of the global luminance state of the image.
[0037] A one-dimensional feature vector is fed into a fully connected multilayer perceptron network with 256 and 64 hidden layer nodes, respectively. At the output layer, a sigmoid function is used to map this vector into a normalized parameter vector containing two elements, both ranging from 0 to 1. The two elements of this normalized parameter vector are decoupled. The first value is mapped proportionally to the effective exposure time range, set to 500 microseconds to 5000 microseconds. The second value is mapped proportionally to the initial analog gain, corresponding to an analog gain setting range of 1 dB to 12 dB. These two sets of continuous variables constitute the initial photometric reference for the environment to be calibrated. It should be noted that the effective exposure time range of 500 microseconds to 5000 microseconds and the analog gain setting range of 1 dB to 12 dB were obtained by conducting photoelectric response calibration experiments on glass bottle samples of different thicknesses at the actual operating speed of the production line. This ensures that within the exposure time limit without motion blur, the dark area luminance information enters the effective linear conversion range of the industrial camera image sensor through appropriate analog gain amplification.
[0038] In an optional embodiment, the control point coordinates and first derivative of a piecewise cubic Hermitian interpolation curve with monotonically increasing grayscale channels are constructed by outputting the tone prediction branch. Specifically, N horizontal coordinate positions are uniformly preset within the grayscale value range as fixed horizontal coordinates for the control point coordinates; a fully connected network branch corresponding to the grayscale channel is derived from the deep image features extracted by the parameter prediction model; for each fully connected network branch, N non-negative vertical coordinate offsets are output through the fully connected layer, and combined with the fixed horizontal coordinates, a set of control point coordinates for the grayscale channel is constructed; the non-negative vertical coordinate offsets are accumulated to ensure the monotonically increasing characteristic of the curve, and the first derivative is calculated based on the secant slope constraint between adjacent control points, outputting the control point coordinates and first derivative of the grayscale channel.
[0039] The grayscale values of the image are normalized to a range of 0 to 1, and a preset number of values are uniformly applied within this continuous range. The x-coordinate positions are fixed at a set of 0, 0.143, 0.286, 0.429, 0.571, 0.714, 0.857, and 1. These fixed nodes provide a baseline for piecewise cubic Hermitian interpolation. A separate tone prediction fully connected layer branch is derived in parallel from the 512-dimensional deep feature vector generated after global average pooling. After a fully connected operation, the tone prediction fully connected layer branch is connected to a linear rectified activation function layer, outputting a sequence of eight non-negative y-coordinate offsets. The non-negativity of the y-coordinate offset sequence prevents color level flipping and black-and-white inversion anomalies in the rendered image.
[0040] After obtaining this set of non-negative offsets, an element-wise accumulation operation is performed along the gray-level increasing direction to calculate the actual ordinate value of each node. To constrain the overall mapping interval to a valid gray-level output domain, all accumulated ordinate sequences need to be uniformly divided by the maximum sum and then normalized to construct a monotonically increasing set of gray-level channel control point coordinates defined between 0 and 1. The secant slopes between adjacent control points are calculated, and the first derivative at each control point is determined using a band-limited central difference algorithm. If adjacent secant slopes have opposite signs or one of the secant slopes is 0, the first derivative at the corresponding node is set to 0. This truncation process reduces artifacts and ringing overshoot caused by traditional cubic spline interpolation at high-contrast edges and identifies the reference function parameters guiding the nonlinear photometric correction of the image.
[0041] S2. Analyze the tone correction vector and generate the final camera parameters.
[0042] In an optional embodiment, the control point coordinates and first derivatives are used to construct a tone correction vector; the initial exposure time, initial simulation gain, and tone correction vector are input to the parameter fusion module, and the final exposure time and final simulation gain are adjusted and generated through an attention mechanism; the final exposure time, final simulation gain, and piecewise cubic Hermite interpolation curve are output for controlling industrial camera acquisition and image processing.
[0043] The coordinates and first derivatives of the control points output by the tone prediction branch are analyzed analytically. The difference in ordinates between adjacent control points is calculated, as well as the change in the first derivative between adjacent control points. Then, the difference in ordinates and the change in the first derivative are concatenated along the feature dimension to obtain a tone correction vector representing the global grayscale mapping relationship of the image. To reduce the impact of different numerical ranges on subsequent network learning, the tone correction vector can be normalized.
[0044] The parameter fusion module employs a multilayer perceptron and attention mechanism to concatenate the initial exposure time, initial analog gain, and tone correction vector along the feature dimension into a one-dimensional fused feature vector. This fused feature vector is input into a fully connected network, which learns the importance weight distribution of different feature dimensions and adjusts the weights accordingly. The adjusted fused feature vector is then input into a multilayer perceptron network composed of fully connected layers, and outputs a 2-dimensional weight coefficient vector through a hyperbolic tangent activation function. Two elements from this weight coefficient vector are used as relative compensation coefficients for the exposure time and analog gain, respectively. These relative compensation coefficients are multiplied by the initial exposure time and initial analog gain to obtain the compensation increment. This compensation increment is then superimposed on the corresponding initial parameters, and the final exposure time and final analog gain are obtained after limiting the values within the allowable range of the industrial camera.
[0045] Using control point coordinates and first derivatives, a lookup table containing 256 discrete mapping values—the piecewise cubic Hermitian interpolation curve—is generated using a piecewise cubic Hermitian interpolation function or an equivalent algorithm. The final exposure time and final analog gain are then written to the industrial camera's hardware registers via an application programming interface (API) provided by the camera manufacturer, such as the GenICam standard library function based on the C++ programming language, completing the exposure and gain parameter settings for the industrial camera hardware. It should be noted that the 256 discrete mapping values are calibrated based on the pixel value range of a typical 8-bit grayscale image to ensure coverage of all possible pixel value mapping requirements from 0 to 255. The industrial camera acquires images based on the new parameters and uses the generated lookup table to perform global grayscale mapping on the acquired images, completing the tone correction image processing for the glass bottle image.
[0046] In an optional embodiment, the coordinates of the analytical control points and their first derivatives constitute a tone correction vector. Specifically, the difference in the ordinates between adjacent control points within the grayscale channel is calculated to represent the step amplitude of the local curve; the change in the first derivative between adjacent control points within the grayscale channel is calculated to represent the curvature change of the local curve; and all the differences in the ordinates of the grayscale channels and the changes in the first derivatives are concatenated to generate a one-dimensional continuous feature vector as the tone correction vector representing the intensity of the global grayscale transformation.
[0047] For the constructed interpolation curve parameter array consisting of 8 control points, the analytical process performs a first-order discrete difference operation along the positive X-axis, sequentially calculating the ordinate differences between 7 adjacent control points. Since all ordinates have been normalized to the interval of 0 to 1 and monotonically increased, the calculated ordinate differences are non-negative, representing the local contrast stretching or compression amplitude within each adjacent grayscale segment. For the first-order derivative sequence of the 8 control points representing the slope characteristics, an adjacent node subtraction operation is performed to obtain 7 first-order derivative changes representing the slope difference. These parameters mathematically approximate the local curvature characteristics of the interpolation curve, approximating the second derivative, and can identify structural bending details caused by overexposure suppression or underexposure brightening during nonlinear contrast transformation. After feature analysis, a tensor merging function is used to perform one-dimensional data concatenation along the feature dimension using the 7-element ordinate difference sequence and the 7-element first-order derivative change sequence. The stitching operation combines two independent arrays into a one-dimensional continuous feature vector with a total length of 14. This continuous feature vector measures the intensity of nonlinear grayscale transformations throughout the image mapping process and embeds the gradient distribution of local photometric information, serving as the tone correction vector for subsequent joint tuning.
[0048] Reference Figure 3The paper presents a histogram showing the eigenvalue height distribution of 14 different eigenvectors. The eigenvalues for the first seven dimensions are generally greater than 0 and exhibit significant fluctuations. The eigenvalues for the latter seven dimensions are mainly concentrated around 0, with a noticeable negative distribution in the last few dimensions. The positive fluctuations in the first seven dimensions reflect the differences in contrast stretching within each grayscale segment, while the negative values in the latter seven dimensions reflect a decrease in the slope of the local mapping curve, i.e., structural curvature bending. It is demonstrated that the tone correction vector, composed of the difference in the ordinate and the change in the first derivative, can accurately capture the local photometric distribution differences and migration gradients in nonlinear grayscale transformations, providing accurate photometric feature priors for subsequent joint parameter tuning.
[0049] In an optional embodiment, the initial exposure time, initial simulation gain, and tone correction vector are input into a parameter fusion module, which adjusts and generates the final exposure time and final simulation gain through an attention mechanism. Specifically, the initial exposure time, initial simulation gain, and tone correction vector are concatenated to form a fused feature vector; this fused feature vector is input into a multilayer perceptron network composed of fully connected layers, mapped by a Tanh activation function, and outputs a 2-dimensional weight coefficient vector, the values of which are limited to between -1 and 1; the two elements of the weight coefficient vector are multiplied by the initial exposure time and initial simulation gain respectively to calculate the compensation increment; the compensation increment is added to the initial exposure time and initial simulation gain respectively, and then subjected to range-limiting processing within the allowable value range of the industrial camera to obtain the updated final exposure time and final simulation gain.
[0050] During this parameter calibration process, the initial exposure time scalar (e.g., 2000 microseconds), the initial simulation gain scalar (e.g., 3 dB), and the 14-dimensional tone correction vector from the network output are extracted. The data from these three sources are sequentially merged using a tensor merging operator to form a 16-dimensional fused feature vector. This concatenation operation achieves a joint expression between the initial photometric hardware parameters and the grayscale mapping features. The 16-dimensional fused feature vector is then fed into a multilayer perceptron network with 32, 16, and 2 nodes respectively. It should be noted that the number of nodes in the multilayer perceptron network was set to 32, 16, and 2 based on calibration verification under model structure search experiments, enabling a smooth dimensionality reduction mapping from 16-dimensional features to 2-dimensional adjustment coefficients with minimal computational overhead. The network applies a hyperbolic tangent activation function for nonlinear activation at the output node, outputting a weight coefficient vector with dimension 2. The value of this weight coefficient vector is limited to a closed interval between -1 and 1, which is used to provide a percentage modulation factor with positive and negative bidirectional scaling capabilities. The limitation of the weight coefficient vector value to the interval between -1 and 1 is based on the inherent mathematical range characteristics of the hyperbolic tangent activation function, which enables symmetrical bidirectional adjustment of exposure and gain by inverse reduction and positive increase.
[0051] The compensation phase begins. The first element of the weighting coefficient vector, such as -0.15, is multiplied by the initial exposure time scalar to generate a time compensation increment of -300 microseconds. The second element is multiplied by the initial analog gain to obtain the gain compensation increment. The time compensation increment and the gain compensation increment are then added together and fed back to their respective initial parameter base values. To prevent the industrial camera from malfunctioning due to parameters exceeding the allowable range, the superimposed exposure time and analog gain are limited. For example, the exposure time is limited to the range of 500 to 5000 microseconds, and the analog gain is limited to the range of 1 to 12 dB, or limited according to the actual allowable range of the industrial camera hardware. The value calculated after closed-loop constraints is used as the final exposure time, such as 1700 microseconds, and the final analog gain output, which is used to trigger the industrial camera's shutter action and photoelectric gain conversion.
[0052] S3. Render the calibration image, calculate the loss, and optimize the prediction model.
[0053] In an optional embodiment, during parameter prediction model training, a differentiable photometric rendering engine converts the final exposure time and final simulated gain into relative photometric adjustment coefficients acting on image grayscale based on the industrial camera calibration relationship. A differentiable photometric transformation is then performed on the backlight reference image channel in the input tensor using a piecewise cubic Hermitian interpolation curve to generate a calibration image. A pre-trained segmentation network is used to obtain a defect probability map of the calibration image. Based on the defect probability map, the local contrast variance and luminance information entropy are calculated. The reciprocal of the local contrast variance and the luminance information entropy are weighted and summed to form the total loss, which is then used to optimize the parameter prediction model through backpropagation.
[0054] The differentiable photometric rendering engine is built using tensor operations to ensure that gradients can be backpropagated from the calibration image to the parameter prediction model during training. Specifically, the reference exposure time and reference simulated gain during the acquisition of the backlight reference image are read or recorded. Based on the industrial camera calibration relationship, the ratio of the final exposure time to the reference exposure time is determined as the relative exposure ratio, and the change in the final simulated gain relative to the reference simulated gain is converted into a relative linear gain ratio. The relative exposure ratio is then multiplied by the relative linear gain ratio to obtain the relative photometric adjustment coefficient acting on the image grayscale. Based on the relative photometric adjustment coefficient, pixel-by-pixel photometric adjustment is performed on the normalized backlight reference image channel, and the adjusted pixel values are input into a differentiable cubic Hermite interpolation function determined by control points and the first derivative for nonlinear tone mapping. Subsequently, the mapping result is restricted to a grayscale range of 0 to 1 to generate a calibration image.
[0055] The pre-trained glass bottle defect segmentation network employs a U-shaped network architecture, the UNet model, trained and converged on a large glass bottle defect dataset. The calibration image is input into the UNet model. The last layer of the UNet model outputs a defect probability map with pixel-level values between 0 and 1 using the sigmoid function. The value of each pixel in the defect probability map represents the probability that the corresponding location belongs to a defect region. During the training loss calculation, the defect probability value of each pixel is used as a continuous high-probability weight for the corresponding pixel in the defect texture salience calculation, while the value obtained by subtracting the defect probability value from 1 is used as a continuous low-probability weight for the corresponding pixel in the background uniformity calculation. During the parameter prediction model training, the network parameters of the pre-trained glass bottle defect segmentation network remain frozen and are only used to generate the defect probability map based on the calibration image and propagate the loss gradient to the calibration image.
[0056] Based on continuous high-probability weights, a weighted average of the gray values of each pixel in the calibration image is calculated, and the weighted squared deviation of each pixel's gray value relative to the weighted gray mean is calculated to obtain the local contrast variance. Based on continuous low-probability weights, a weighted statistical method is used to distribute the gray values of each pixel in the calibration image. The soft histogram weighted statistical method is used to continuously allocate the pixel gray values to multiple gray ranges, and the luminance information entropy is calculated based on the normalized weighted probability of each gray range.
[0057] The inverse of the local contrast variance and the luminance information entropy are multiplied by their respective hyperparameter weights and then summed to obtain the scalar total loss value. Backpropagation is performed based on the scalar total loss value to calculate the gradient of the learnable weights in the parameter prediction model. The network weights of the parameter prediction model are then updated using an optimization algorithm to complete one iteration of training.
[0058] In an optional embodiment, local contrast variance and luminance entropy are calculated based on the defect probability map. Specifically, according to the defect probability value of each pixel in the defect probability map, the defect probability value is used as a continuous high-probability weight for the corresponding pixel to participate in the defect texture prominence calculation, and the value obtained by subtracting the defect probability value from 1 is used as a continuous low-probability weight for the corresponding pixel to participate in the background uniformity calculation. Based on the continuous high-probability weight, the gray values of each pixel in the calibration image are weighted and averaged to obtain the weighted gray mean under the high-probability weight, and the weighted squared deviation of each pixel's gray value relative to the weighted gray mean is calculated to obtain the local contrast variance. Based on the continuous low-probability weight, the gray distribution of each pixel in the calibration image is weighted and statistically analyzed to calculate the luminance entropy.
[0059] To assess the ability of photometric calibration results to identify defect features, a defect segmentation network, such as a U-shaped convolutional network model, was used to output a pixel-level defect probability map with a resolution of 512×512 pixels. During the training phase, each pixel probability value in the defect probability map was used as a continuous high-probability weight, and the value obtained by subtracting the pixel probability value from 1 was used as a continuous low-probability weight.
[0060] Based on continuous high-probability weights, the grayscale values of all pixels in the calibration image are statistically weighted, and the weighted squared deviation of each pixel's grayscale value relative to the weighted grayscale mean under high-probability weights is calculated to obtain the local contrast variance. The local contrast variance is a weighted variance based on all pixels in the image and focused to the suspected defect location by continuous high-probability weights. Since pixels with a higher defect probability account for a larger proportion in the calculation, it can reflect the intensity of grayscale jumps in the suspected defect area.
[0061] Based on continuous low-probability weights, a weighted statistical analysis is performed on the gray-level distribution of all pixels in the calibration image, with pixels having a lower defect probability receiving greater weight in the statistical process. Specifically, the gray-level range of 0 to 1 is divided into multiple continuous gray-level intervals, and the center gray-level value of each interval is determined. For any pixel in the calibration image, the difference between the normalized gray-level value of the current pixel and the center gray-level value of each gray-level interval is calculated. Based on the difference, the initial assignment value of the current pixel relative to each gray-level interval is calculated using a Gaussian kernel function; the smaller the difference, the larger the initial assignment value. Then, all the initial assignment values corresponding to the current pixel are normalized so that the sum of the assignment weights of the initial assignment values in each gray-level interval is 1, thus obtaining the soft assignment weight corresponding to the current pixel.
[0062] The soft-assigned weights are multiplied by the consecutive low-probability weights corresponding to the current pixel, and then accumulated across all pixels in the image to obtain weighted statistical values for each grayscale interval. These weighted statistical values are then normalized to obtain the probability values corresponding to each grayscale interval. These probability values are then substituted into the Shannon entropy formula (base 2), with a small bias term added to the logarithmic term to avoid numerical anomalies. The resulting summation, expressed in bits, yields the luminance entropy. It should be noted that the small bias term, for example, set to 1e-7, is calibrated based on the numerical stability of deep learning to prevent the logarithmic function from generating infinite gradients or meaningless values when the input probability is 0, ensuring the stability of the backpropagation process. The luminance entropy characterizes the dispersion of grayscale distribution in background-prone areas; a decrease in entropy indicates a more concentrated distribution of background pixels and better uniformity of background light.
[0063] The experimental setup was a 20-megapixel global shutter monochrome industrial camera with a 1-inch target area and a blue LED surface light source. 500 glass bottle samples with scratches and micro-cracks were used as the test set. The control group algorithm only used a multi-layer convolutional network to output the initial exposure time and initial simulated gain to control the hardware for image acquisition. The experimental group algorithm added a tone prediction branch and an attention mechanism. It generated a tone correction vector by analyzing the control points and first derivatives of a piecewise cubic Hermitian interpolation curve. This correction vector was then fused with the initial exposure parameters and mapped through a multi-layer perceptron network and a hyperbolic tangent activation function to generate the final exposure time and final simulated gain, including time compensation increments and gain compensation increments, for image acquisition.
[0064] Reference Figure 4 In evaluating local contrast variance, the experimental algorithm showed a significant improvement over the control group, with the local contrast variance increasing from 145.2 to 218.6. In evaluating luminance entropy, the experimental algorithm showed a significant decrease compared to the control group, with the luminance entropy decreasing from 4.12 to 2.35. In evaluating defect segmentation accuracy, the experimental algorithm showed a further increase compared to the control group, with the defect segmentation accuracy rising from 88.5% to 96.8%. The increase in local contrast variance reflects more dramatic pixel grayscale jumps within suspected defect areas, proving that the calibration mechanism established by the experimental algorithm can enhance the prominence of small defect boundaries. The decrease in luminance entropy reflects a more concentrated grayscale distribution in defect-free background areas, proving that the joint optimization mechanism improves the illumination uniformity of background areas. The improvement in defect segmentation accuracy reflects an increase in the accuracy of feature extraction from the segmentation network, proving that the joint optimization mechanism can improve the detection system's ability to identify weak defects.
[0065] The experimental group extracted a tone correction vector and incorporated the migration gradient distribution of local photometric information as a feature prior into a deep network, establishing a joint optimization relationship between hardware exposure parameters and image nonlinear contrast transformation. The attention mechanism based on a multilayer perceptron outputs a weight coefficient vector with positive and negative scaling capabilities, which can correct the initial hardware parameters and reduce the loss of structural details caused by overexposure suppression or underexposure brightening in conventional photometric estimation. This calibration mechanism can, to some extent, enhance the gray-level jump prominence of small defect boundaries and improve the illumination uniformity of defect-free background areas, making the underlying image quality more suitable for the feature extraction needs of defect segmentation networks.
[0066] It should be noted that those skilled in the art can make various modifications and improvements without departing from the inventive concept, and these all fall within the scope of protection of this invention. Therefore, the scope of protection of this patent should be determined by the appended claims.
Claims
1. An automatic calibration method for camera parameters for glass bottle detection, characterized in that, include: S1. Obtain the backlight reference image and structured light deflection image of the glass bottle to be tested, and stitch them together along the channel dimension to form the input tensor; The input tensor parameter prediction model outputs the initial exposure time and initial simulation gain through the photometric prediction branch; the control point coordinates and first derivative of the piecewise cubic Hermitian interpolation curve with monotonically increasing grayscale channels are output through the tone prediction branch; S2, the analytical control point coordinates and first derivative constitute the tone correction vector; the initial exposure time, initial simulation gain and tone correction vector are input parameter fusion module, and the final exposure time and final simulation gain are generated through the attention mechanism. The system outputs the final exposure time, final simulated gain, and piecewise cubic Hermitian interpolation curve for controlling camera acquisition and image processing. S3: During parameter prediction model training, the final exposure time and final simulated gain are converted into relative photometric adjustment coefficients using a differentiable photometric rendering engine. Combined with the piecewise cubic Hermitian interpolation curve, a differentiable photometric transformation is performed on the backlight reference image to generate a calibration image. A pre-trained segmentation network is used to obtain the defect probability map of the calibration image. Based on the defect probability map, the local contrast variance and luminance information entropy are calculated. The reciprocal of the local contrast variance and the luminance information entropy are weighted and summed to form the total loss. Backpropagation is then used to optimize the parameter prediction model.
2. The automatic calibration method for camera parameters for glass bottle detection according to claim 1, characterized in that, The process of acquiring the backlight reference image and structured light deflection image of the glass bottle under test, and stitching them together along the channel dimension to form an input tensor, includes: acquiring a transmission image of the glass bottle and extracting a grayscale matrix to generate a single-channel backlight reference image; acquiring three-dimensional reconstructed deflection information and converting it into a single-channel structured light deflection image; applying a scale normalization function to adjust and align the resolution of the backlight reference image and the structured light deflection image to a preset square resolution; and stitching the adjusted backlight reference image as the first channel and the adjusted structured light deflection image as the second channel side-by-side to generate a three-dimensional matrix as the input tensor.
3. The automatic calibration method for camera parameters for glass bottle detection according to claim 1, characterized in that, The step of outputting the initial exposure time and initial simulated gain through the photometric prediction branch includes: inputting the input tensor into a multi-layer convolutional downsampling network to extract deep image features and output a feature map; performing a global average pooling operation on the feature map to extract a multi-channel one-dimensional feature vector; inputting the one-dimensional feature vector into a fully connected layer and outputting a parameter vector containing two positive values through a non-linear activation function; separating the parameter vector, mapping the first value to the initial exposure time, and mapping the second value to the initial simulated gain.
4. The automatic calibration method for camera parameters for glass bottle detection according to claim 2, characterized in that, The method of constructing the control point coordinates and first derivative of a piecewise cubic Hermitian interpolation curve with monotonically increasing grayscale channels through the output of the tone prediction branch includes: uniformly presetting fixed horizontal coordinates within the grayscale value range; extracting non-negative vertical coordinate offsets from the fully connected network branches of the corresponding grayscale channels from the deep image features extracted by the parameter prediction model; accumulating the non-negative vertical coordinate offsets and constructing the control point coordinates in combination with the fixed horizontal coordinates; and calculating the first derivative based on the secant slope constraint between adjacent control points.
5. The automatic calibration method for camera parameters for glass bottle detection according to claim 1, characterized in that, The step of analyzing the control point coordinates and the first derivative to form a tone correction vector includes: calculating the difference in ordinates between adjacent control points in the grayscale channel; calculating the change in the first derivative between adjacent control points in the grayscale channel; and concatenating all the differences in ordinates with the change in the first derivative to generate a one-dimensional continuous feature vector as the tone correction vector.
6. The automatic calibration method for camera parameters for glass bottle detection according to claim 1, characterized in that, The module that fuses the initial exposure time, the initial simulation gain, and the tone correction vector input parameters, and adjusts and generates the final exposure time and the final simulation gain through an attention mechanism, includes: concatenating the initial exposure time, the initial simulation gain, and the tone correction vector to form a fused feature vector; inputting the fused feature vector into a multilayer perceptron network, and outputting a weight coefficient vector through a hyperbolic tangent activation function; multiplying the elements of the weight coefficient vector by the initial exposure time and the initial simulation gain respectively to calculate the compensation increment; and superimposing the compensation increment onto the corresponding initial parameters and performing amplitude limiting to obtain the final exposure time and the final simulation gain.
7. The automatic calibration method for camera parameters for glass bottle detection according to claim 5, characterized in that, The step of calculating the local contrast variance and luminance information entropy based on the defect probability map includes: using the defect probability value in the defect probability map as a continuous high probability weight, and using the value obtained by subtracting the defect probability value from 1 as a continuous low probability weight; performing a weighted average of the gray values of each pixel in the calibration image based on the continuous high probability weight and calculating the weighted squared deviation to obtain the local contrast variance; and performing a weighted statistical analysis of the gray distribution of each pixel in the calibration image based on the continuous low probability weight to obtain the luminance information entropy.
8. The automatic calibration method for camera parameters for glass bottle detection according to claim 2, characterized in that, The step of acquiring the transmission image of the glass bottle and extracting the grayscale matrix to generate the single-channel backlight reference image includes: using a camera to photograph the glass bottle under backlight illumination to acquire the backlight reference image; the step of acquiring the three-dimensional reconstructed deflection information and converting it into the single-channel structured light deflection image includes: using a stripe projector to project phase-shifted stripes and simultaneously photographing to acquire the structured light deflection image.
9. The automatic calibration method for camera parameters for glass bottle detection according to claim 1, characterized in that, The step of converting the final exposure time and the final simulated gain into a relative photometric adjustment coefficient includes: obtaining a reference exposure time and a reference simulated gain; determining the ratio of the final exposure time to the reference exposure time as a relative exposure ratio; converting the change in the final simulated gain relative to the reference simulated gain into a relative linear gain ratio; and multiplying the relative exposure ratio by the relative linear gain ratio to obtain the relative photometric adjustment coefficient.
10. The automatic calibration method for camera parameters for glass bottle detection according to claim 7, characterized in that, The step of obtaining the luminance information entropy by weighting the grayscale distribution of each pixel in the calibration image based on the continuous low probability weights includes: continuously allocating the pixel grayscale values to multiple grayscale intervals using a soft histogram weighted statistical method, and calculating the probability value corresponding to each grayscale interval; substituting the probability value into the Shannon information entropy calculation formula with base 2, adding a small bias term to the logarithmic term, and then accumulating the terms one by one to obtain the luminance information entropy.