A video image change detection method based on artificial intelligence
Through artificial intelligence technology and OpenCV deep learning model, combined with structural similarity index and feature vector comparison, it solves the problem of limited performance of traditional video image change detection in complex scenes, realizes efficient change detection and personalized monitoring requirements, and improves Improve the intelligence and efficiency of the monitoring system.
Patent Information
- Application Number
- CN202410921424.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-07-10
AI Technical Summary
Traditional video image change detection technology has limited performance when processing complex scenes, is difficult to accurately extract features, and cannot meet the needs of efficient processing of large-scale video data and real-time video streams. In particular, there is a bottleneck in personalized target recognition.
An artificial intelligence-based video image change detection method is used to collect and process video frame images by establishing a connection with the video streaming server. OpenCV and deep learning models are used for image grayscale, enhancement and feature extraction, combined with structural similarity index and features. Vector comparison enables change detection and supports personalized message notifications and intelligent analysis.
It improves the accuracy and adaptability of video image change detection, can detect abnormal changes in time, improves the intelligence and efficiency of the monitoring system, and meets the change detection needs in complex scenarios.
Smart Images

Figure CN118470613B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of video image change detection, and in particular to a video image change detection method based on artificial intelligence. Background Art
[0002] With the continuous development of technologies such as high-definition cameras, network technology, and artificial intelligence, more accurate and reliable monitoring screen analysis can be provided for video image change detection. It is widely used in security, transportation, retail and other fields, realizing automatic detection and recording of abnormal events, and improving the efficiency and intelligence level of video analysis systems.
[0003] Traditional video image change detection technology mainly relies on manually designed feature extraction methods, such as a real-time change detection method and system for aerial video images disclosed in the invention patent with announcement number CN114973028B and a video-based panoramic image change detection method disclosed in the invention patent with announcement number CN111369495B, both of which can realize image change detection.
[0004] However, while these methods perform well in specific scenarios, their performance is often limited when dealing with complex and changeable video data. For example, when there are problems such as illumination changes, occlusions, and angle changes in the video scene, these methods may have difficulty accurately extracting meaningful features, resulting in inaccurate comparison results.
[0005] In terms of application scenarios, traditional video image change detection technology is mainly used in security monitoring, target tracking and other fields. With the popularization of video surveillance systems, the improvement of intelligent needs and the popularization of unmanned scenes, the requirements for video image change detection technology are also getting higher and higher. Traditional detection methods still have bottlenecks in processing large-scale video data, real-time video streams, personalized target recognition, etc., and it is difficult to meet the needs of actual applications. Summary of the invention
[0006] In order to solve the above technical problems, the present invention provides a video image change detection method based on artificial intelligence that realizes personalized monitoring needs and uses artificial intelligence technology to perform intelligent perception and analysis of monitoring videos, thereby improving the intelligence level of the monitoring system, automatically discovering abnormal situations and providing timely notifications, and greatly improving the efficiency and reliability of the monitoring system.
[0007] A video image change detection method based on artificial intelligence of the present invention comprises the following steps:
[0008] Step 1: Establish a connection with the video streaming server:
[0009] Step 1-1, parsing the video stream address: first parse the video stream address and extract the server address, port number and protocol type information;
[0010] Step 1-2, establish a network connection: according to the extracted information, try to establish a network connection with the video streaming server through the TCP protocol or the UDP protocol;
[0011] Step 1-3, send authentication information: If the video streaming server requires authentication, send authentication information to the server for verification after establishing the connection;
[0012] Step 1-4, negotiate transmission parameters: After the connection is established, the client and server need to negotiate transmission parameters;
[0013] Step 1-5, start video stream transmission: After parameter negotiation is completed, the server starts sending video stream data to the client, and the client receives and decodes the data;
[0014] Step 2: Video stream image acquisition:
[0015] Step 2-1, timed video frame image acquisition:
[0016] (1) Set the timer: First, set the time interval for image acquisition. The default value is 1 minute. Use the APScheduler library in Python to schedule and execute scheduled tasks. Set the timer to automatically capture video images according to the time interval for image acquisition.
[0017] (2) Capture video stream: After the timer is triggered, the system starts capturing the video stream;
[0018] (3) Extract image frames: From the captured video stream, use the OpenCV library read() function to capture image frames from the video stream according to the time interval set by the timer;
[0019] (4) Saving and processing: adjust all image frames to a uniform size, and use the cv2.imwrite() function of the computer vision library OpenCV to save the extracted image frames to a specified storage location for subsequent analysis and processing. At the same time, the image frames can also be pre-processed as needed;
[0020] Step 2-2: Automatic video key frame image acquisition:
[0021] (1) Video preprocessing: Use the OpenCV library read() function to read individual frames from the video stream. The video frame rate defaults to 25fps to reduce the amount of calculation or adapt to specific analysis requirements. Use filters to reduce the noise of the video frames. The noise reduction methods used use mean filtering, Gaussian filtering, and median filtering to reduce the noise of the video frames.
[0022] (2) Key frame prediction:
[0023] The key frame selection is performed by combining the three-frame difference method with the recurrent neural network. The three-frame difference method is used to capture the inter-frame differences between adjacent frames after video preprocessing to form three-frame differences. The three-frame difference map is used as the input of the recurrent neural network model. The cyclic structure of the recurrent neural network is used to capture the temporal dependency between frames, learn the dynamic changes between video frames, understand the evolution of video content, and improve the accuracy of key frame detection by combining timing information and inter-frame differences.
[0024] Step 3: Image acquisition and processing:
[0025] Step 3-1: Image grayscale processing:
[0026] Image grayscale processing is to convert a color image into a grayscale image. Its purpose is to convert the image from three channels to a single channel to simplify the image processing task and reduce the amount of calculation. This method uses the fusion method of the maximum value method and the weighted average value to traverse the pixels in the original image and perform grayscale processing respectively. By using the fusion method of the maximum value method and the weighted average value, the pixels in the original image are traversed and grayscaled respectively. The fusion method of the maximum value method and the weighted average value is used to retain the image details and contrast in the grayscale process, reduce color deviation, and improve the adaptability and robustness of the grayscale method. The formula is:
[0027] ;
[0028] Among them, R, G, B are the corresponding value ranges [0,255] in the RGB model, and T is the weight of the maximum value method;
[0029] Step 3-2, image enhancement:
[0030] The grayscale image after grayscale processing is subjected to image equalization transformation based on the histogram equalization method to achieve image enhancement. The histogram equalization method realizes nonlinear stretching of the image by widening the grayscale with a large number of pixels in the image and reducing the grayscale with a small number of pixels, and redistributes the image pixel values so that the number of pixels within a certain grayscale range is roughly the same. It can effectively suppress background noise, reduce image blur and quality degradation caused by background elements, and significantly enhance the contrast of the image, making the grayscale level more obvious and the details clearer, which is helpful for subsequent comparison and analysis of image content;
[0031] Step 4: Change detection configuration:
[0032] Step 4-1, Change detection configuration:
[0033] Through the detection area configuration, you can perform video designated area detection, minimum detection area and sensitivity settings. The designated area defaults to the entire area. The larger the sensitivity value, the higher the sensitivity. The value range is [0,100] and the default is 100.
[0034] Step 4-2, Whitelist target training:
[0035] Whitelist target training uses the YOLOv9 target detection model. Based on the user's actual application scenario, you can upload a set of images that meet the standards through the Web application and perform a custom data set training model to filter whitelist targets in the process of video image change detection based on the user's actual application;
[0036] Step 5: Detection area selection:
[0037] Step 5-1: According to the detection area pixel coordinates (X, Y, W, H) configured for the detection area in the detection video, the detection area pixel value of the image is calculated. The formula is as follows:
[0038] ;
[0039] Where x0 is the horizontal pixel coordinate, y0 is the vertical pixel coordinate, W is the region width, and H is the region height;
[0040] Step 5-2, Whitelist target filtering:
[0041] Based on the model library obtained by whitelist target training, the whitelist targets in the collected images are identified based on the YOLOv9 algorithm to obtain the target matching degree and the target area;
[0042] Step 6: Image change detection:
[0043] Step 6-1: Image structure similarity comparison:
[0044] The calculation of the structural similarity index is based on brightness, contrast and structure. First, the original image and the reference image are divided into small blocks of the same size. Then, for each small block, the similarity of its brightness, contrast and structure is calculated respectively. The brightness similarity is calculated using the mean and variance of the brightness, and the contrast similarity is calculated using the mean and variance of the contrast. The structural similarity is obtained by calculating the covariance between the original image and the reference image and the variance of the two. Then, the similarity of each small block is weighted averaged to obtain the similarity of the entire image. The value range of the structural similarity index S1 is [-1,1], where 1 means that the two images are exactly the same, and -1 means that the two images are completely different. The closer the value is to 1, the higher the structural similarity of the two images, and the closer the value is to -1, the lower the structural similarity.
[0045] The formula is:
[0046] ;
[0047] Among them, x and y are the two images detected, μ x and μ y is the mean of x and y, is the variance of x and y, σ xy is the covariance of images x and y;
[0048] Step 6-2: Image feature extraction and matching:
[0049] Use the deep learning-based artificial intelligence model, ResNet deep convolutional neural network, to extract and match the features of the original image and the reference image;
[0050] Step 6-3, calculate the comprehensive similarity:
[0051] By setting the fusion weight α, the default value of which is 0.75, the image structure similarity S1 and the feature vector similarity S2 are calculated by setting the weight α;
[0052] The formula is: ;
[0053] Among them, α is the fusion weight, S1 is the structural similarity, and S2 is the feature vector similarity;
[0054] This method can combine the image comparison capability of image structure similarity comparison and the feature extraction capability of artificial intelligence models to improve the accuracy and comprehensiveness of information on detected changed areas;
[0055] Step 6-4: Determine and save the changed area:
[0056] According to the above steps, the comprehensive similarity S is obtained, and the changed area is selected. When the comprehensive similarity S is less than 0.5, the area is determined to be a changed area;
[0057] The formula is: ;
[0058] Among them, S is the comprehensive similarity, O is the changed area when the value is 1, and the non-changed area when it is 0;
[0059] When it is determined to be a changed area, first use the function cv2.boundingRect() in OpenCV to obtain the coordinates of the changed area (x1, y1, w1, h1), then use the function cv2.rectangle() in OpenCV to draw a rectangular bounding box on the original image, and use the function cv2.imwrite() in OpenCV to generate the annotated image after annotation. Finally, the original image, the changed image, the annotated image, the change time interval, the pixel area of the changed area, the pixel coordinates of the changed area and the comprehensive recognition information are stored in the database;
[0060] Step 7: Detection change information notification:
[0061] When abnormal or important changes are detected in the video image, the original image, the changed image, the annotated image, the change time interval, the pixel area of the changed area, the pixel coordinates of the changed area and the comprehensive recognition degree are set according to the specific business scenario, so as to send accurate notifications when changes are detected. It supports multiple notification methods such as email, SMS, phone and instant messaging, which can timely detect abnormal or important changes in the video, respond quickly, improve efficiency and reduce risks;
[0062] Step 8: Record and analyze test information:
[0063] When abnormal or important changes are detected in the image in the video, the change log records will be stored and combined with the artificial intelligence model, the output results of the artificial intelligence model will be integrated into the log system, and the intelligent perception results will be integrated with traditional log data to form a complete log record data set; machine learning and data mining techniques will be used to perform intelligent analysis of log data, perform anomaly detection analysis, extract key features and conduct in-depth analysis, and provide an interactive visualization interface to support users to customize viewing and analysis of data according to their needs, and display the intelligent analysis results in the form of charts and dashboards for users to intuitively understand and analyze.
[0064] Preferably, the noise reduction method used adopts mean filtering, Gaussian filtering and median filtering methods to perform video frame noise reduction, and the specific steps are as follows:
[0065] First, a smaller filter is selected by using mean filtering to perform preliminary smoothing on the video frame to remove part of the noise in order to balance the denoising effect and the retention of image details;
[0066] The mean filter smoothes the image by calculating the average value of the neighborhood around the pixel. It is suitable for removing mild noise. The formula is:
[0067] ;
[0068] Among them, Input(x,y) represents the pixel value at position (x,y) in the input image, Output(x,y) represents the pixel value at position (x,y) in the output image, n is the size of the filter, i and j represent the coordinates (i,j) of the pixel point in the surrounding area of (x,y), and the sum of the pixels in the surrounding area is calculated according to the value of the filter;
[0069] After the mean filter, a Gaussian filter is applied to select an appropriate Gaussian kernel size and standard deviation to ensure the denoising effect and preserve image details as much as possible, and the video frame is further smoothed to remove more noise;
[0070] The Gaussian filter uses Gaussian distribution to calculate the weights of pixels in the neighborhood, which is suitable for a greater degree of noise removal. The formula is:
[0071] ;
[0072] Where Input(x,y) represents the pixel value at position (x,y) in the input image, Output(x,y) represents the pixel value at position (x,y) in the output image, G(i,j) is the Gaussian distribution function, and the weight of the pixel coordinate position (i,j) in the image is the coordinate position of the input (x,y) coordinate.
[0073] Finally, the median filter is applied to remove salt and pepper noise, which has a good effect. The final denoising process of the video frame can further improve the image quality.
[0074] The median filter sorts the pixel values in the neighborhood around the pixel and then takes the middle value as the output pixel value. The formula is:
[0075] ;
[0076] Among them, Input(x,y) represents the pixel value at position (x,y) in the input image, Output(x,y) represents the pixel value at position (x,y) in the output image, and median(Input(x,y),....,Input(x,y)) represents the median operation;
[0077] The combined use of mean filtering, Gaussian filtering and median filtering methods can effectively remove various noises in video frames, improve image quality, and provide more reliable input for subsequent feature extraction, processing and analysis tasks.
[0078] Preferably, the key frame prediction comprises the following steps:
[0079] First, the difference images between the kth frame and the k-1th frame and the difference images between the k+1th frame and the kth frame are obtained respectively, and then the grayscale image is converted into a binary image. Finally, the obtained binary difference images are subjected to an “AND” operation to obtain three-frame difference images.
[0080] The formula is:
[0081] ;
[0082] Among them, G k (image) is the result image, P k (image) is the k-th frame image, P k-1 (image) is the k-1th frame image, P k+1 (image) is the k+1th frame image;
[0083] Then, a binary classification recurrent neural network model is designed. The output layer of the model uses the built-in sigmoid activation function of the recurrent neural network. The difference map between three frames is input to generate a probability value between 0 and 1. The default threshold T is set to 0.65. When the output probability value is greater than T, the output result is 1, and the current frame is a key frame. Otherwise, the output result is 0, and the current frame is a non-key frame.
[0084] The formula is:
[0085] ;
[0086] Among them, t is the output of the recurrent neural network model, e is a natural constant, and T is the set threshold;
[0087] By setting the threshold T to 0.65 by default, it is possible to ensure the recognition of image change differences while taking into account the influence of some backgrounds on the change differences, and it can be dynamically adjusted according to the needs of practical applications.
[0088] Preferably, the default threshold T is set to 0.65 based on the following reasons: the three-frame difference method can detect moving targets more accurately because the choice of threshold directly affects the binarization result of pixels in the differential image, which in turn affects the final moving target extraction. When the threshold is set too high, some useful changes in the image may be ignored; and when it is set too low, part of the background may be mistaken for a foreground target.
[0089] Preferably, the weight T of the maximum value method of image grayscale processing defaults to 0.6, and the value range is [0,1].
[0090] Preferably, the image enhancement comprises the following steps:
[0091] (1) The grayscale value of the image to be processed at each level of the input image is in the range of [0, L-1], and the value of the corresponding position is obtained after equalization;
[0092] The formula is: L=2 b ;
[0093] Where L is the grayscale level of the image, and b is the number of image bits;
[0094] ;
[0095] Among them, r j is the gray value of the input image, s is the gray value after equalization, j is the gray value pixel, k is the total number of gray value pixels, and T() is the histogram equalization conversion;
[0096] (2) Calculate the probability of occurrence of each class gray value:
[0097] The formula is:
[0098] ;
[0099] Where sum(s) is the number of pixels with grayscale value s in the image, and M and N represent the number of rows and columns of the image, respectively;
[0100] (3) The gray level cumulative distribution function of each probability is used to calculate the cumulative probability of each class gray value.
[0101] The formula is:
[0102] ;
[0103] Among them, r k is the gray level value of the image, p(r j ) is the probability of occurrence of the class gray value in the original image, and j is a temporary variable. The sum of k is calculated in turn. CDF(r k ) is gray level less than or equal to r k The cumulative probability of the pixel;
[0104] (4) Perform image equalization transformation on the gray level of each probability;
[0105] The formula is:
[0106] ;
[0107] Among them, T(r k ) corresponds to the gray level r k The pixel value after equalization, L is the number of gray levels of the image.
[0108] Preferably, the designated area detection step:
[0109] First, the user selects and sets the video stream through the Web application, and uses the cap.read() function in OpenCV to read the video image from the video stream;
[0110] Then, use the cv2.imshow() function in OpenCV to display the video image;
[0111] Finally, according to user needs, use the cv2.rectangle() function in OpenCV to draw the detection area on the video image with the mouse, and save the pixel coordinates of the user-selected video detection area in (X, Y, W, H), where X is the starting horizontal coordinate, Y is the starting vertical coordinate, W is the area width, and H is the area height.
[0112] Preferably, the whitelist target training comprises the following steps:
[0113] (1) Data upload: Users select and upload data sets and model names that meet the specified format, quantity, and quality standards through the web application according to actual needs;
[0114] (2) Data preprocessing and labeling: The uploaded images are resized, normalized, and labeled with target objects. By integrating the Grounding DINO target detection algorithm, the image sets uploaded by users are automatically processed and labeled. After automatic processing, a manual review interface is provided to correct incorrect annotations. After manual review, the data set is automatically divided into training set, validation set, and test set in a ratio of 7:2:1.
[0115] (3) Model training: By reading the training set information uploaded by the user, the model parameters are automatically adjusted according to the characteristics of the data set, and the YOLOv9 configuration file is dynamically generated, including the training set path, model configuration file, and hyperparameters. After the training is completed, the evaluation script is automatically called to evaluate the trained model and the evaluation results are recorded in the training log;
[0116] (4) Model generation: After the training is completed, the model weight file in the weights format obtained through training is automatically saved and added to the user whitelist model library for subsequent video association;
[0117] (5) Model intelligent learning: When collecting video images, select a training model, perform target detection to identify the target object in the video, record its location information and category information, and extract the corresponding target image as a new training sample. Use artificial intelligence technology to automatically identify the changes in the accuracy, recall rate and mAP indicators of the model algorithm to make intelligent decisions. Use the reinforcement learning algorithm to automatically decide whether to trigger model updates. Use active learning strategies to select the most informative samples for model updates. Use transfer learning and domain adaptation technologies to enhance the generalization ability and adaptability of the model. At the same time, through real-time monitoring and real-time update mechanisms, timely trigger model updates to respond to environmental changes, realize intelligent model optimization and improve algorithms to actively select the most informative samples for model updates.
[0118] Through change detection configuration, users can set detection areas and whitelist target filtering according to their needs, and implement intelligent whitelist model update and optimization processes to improve the performance and adaptability of the model and better adapt to changing environments and scenarios.
[0119] Preferably, the whitelist target filtering comprises the following steps:
[0120] (1) Load the pre-trained whitelist target model;
[0121] (2) Input the video image to be detected, use the model.predict() function in the YOLOv9 algorithm to perform target detection on the input image, identify various targets in the image and output target information;
[0122] (3) Use the pre-trained neural network model to extract the feature vector of each detected target;
[0123] (4) Calculate the cosine similarity between the feature vector of the target and the feature vector of the target in the target library. The cosine similarity indicates that the two vectors are closer in direction, that is, the matching degree is higher. When the cosine similarity is greater than 0.75, it is identified as a whitelist target. The cosine similarity calculation formula is:
[0124] ;
[0125] Among them, v1 and v2 are the feature vector of the target and the feature vector of the target in the target library respectively, and ||v|| represents the norm of vector v;
[0126] (5) Filter out targets with cosine similarity greater than 0.75 and determine them as whitelist targets. Use the get_bbox(obj) function to obtain the bounding box coordinates, width, and height of the target, and return the data in the format of (x, y, w, h);
[0127] (6) According to the obtained whitelist target pixel coordinates (x, y, w, h), each pixel (i, j) in the selected detection area is checked to see if it is in the whitelist target area. If it is to be excluded from the selected detection area, the formula is as follows:
[0128] ;
[0129] Where (i, j) is the image pixel region, x is the horizontal pixel coordinate, y is the vertical pixel coordinate, w is the region width, and h is the region height;
[0130] Based on the selection of the detection area, whitelist target filtering is performed to finally obtain the area that needs to be detected for changes.
[0131] Preferably, the extraction and matching of features of the original image and the reference image comprises the following steps:
[0132] (1) For the processed input image, use the preprocess_imag() function to preprocess the image, then use the features method of the model to extract the feature map and output the feature map array;
[0133] (2) Set the ResNet model to evaluation mode using the model.eval() function;
[0134] (3) Use the model’s feature() method to extract feature vectors and convert feature vector arrays;
[0135] Using cosine similarity, the vector similarity S2 is calculated for the feature vector arrays extracted from the original image and the reference image. The value range of S2 is [-1,1], where 1 means that the two images are exactly the same, and -1 means that the two images are completely different. The closer the value is to 1, the higher the structural similarity of the two images; the closer the value is to -1, the lower the structural similarity;
[0136] The formula is:
[0137] ;
[0138] Among them, x and y are the feature image arrays for detecting two images, ∙ represents the dot product of the vectors, and ||x|| and ||y|| are the norms of vectors x and y, respectively.
[0139] Compared with the prior art, the present invention has the following beneficial effects:
[0140] 1. This method uses the deep learning tool computer vision library OpenCV, and adopts two methods: timed video frame image acquisition and automatic video key frame to collect video frame images. Video image frame extraction reduces a large amount of video data, while ensuring that key images are preserved, which plays a key role in improving video detection accuracy and provides important data support for subsequent video image comparison and recognition;
[0141] 2. This method reduces the amount of data, improves image processing efficiency, highlights image details, and enhances image contrast by graying and enhancing the collected images. It can also improve the adaptability to different application scenarios and needs.
[0142] 3. Detection area selection and detection target filtering are performed by configuring detection areas and whitelist targets. Through change detection configuration, some pre-set detection areas or targets can be marked as "whitelists" according to specific scenarios and needs. When performing change detection, only detection areas and non-whitelist targets can be detected, thereby filtering out non-detection areas and whitelist targets. In addition, an intelligent whitelist model update and optimization process can be implemented to improve the performance and adaptability of the model and better adapt to changing environments and scenarios.
[0143] 4. For the collected and processed video frame images, the adjacent frame images are compared by the structural similarity index method and the image feature extraction and vectorization comparison method to perform change detection, which can improve the accuracy, robustness and adaptability of image comparison, effectively detect the change area recognition in the image, and thus more effectively cope with change detection in various complex scenes;
[0144] 5. Use the method of integrating structural similarity index and artificial intelligence to detect changes in the collected images. It can combine the image comparison ability of image structural similarity comparison and the feature extraction ability of artificial intelligence model to detect more accurate and comprehensive change area information;
[0145] 6. You can set personalized message notification templates and notification methods according to specific business scenarios, so that accurate notifications can be sent when changes are detected. It supports multiple notification methods such as email, SMS, phone, instant messaging, etc., which can timely detect abnormal changes or important changes in the video, respond quickly, improve efficiency, and reduce risks;
[0146] 7. Use machine learning and data mining technology to intelligently analyze log data, perform anomaly detection analysis, extract key features and conduct in-depth analysis, and provide an interactive visualization interface to support users to customize viewing and analysis of data according to their needs. BRIEF DESCRIPTION OF THE DRAWINGS
[0147] Figure 1It is a schematic diagram of the process structure of the present invention;
[0148] Figure 2 It is a schematic diagram of the process of establishing a connection with a video streaming server in the present invention;
[0149] Figure 3 It is a schematic diagram of the image acquisition processing flow of the present invention;
[0150] Figure 4 It is a schematic diagram of the structure of the image change detection process of the present invention. DETAILED DESCRIPTION
[0151] In order to facilitate understanding of the present invention, the present invention will be described more fully below with reference to the relevant drawings. The present invention can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the disclosure of the present invention more thorough and comprehensive. Example
[0152] like Figures 1 to 4 As shown, a video image change detection method based on artificial intelligence includes the following steps:
[0153] Step 1: Establish a connection with the video streaming server:
[0154] Establishing connection information with the video streaming server supports HLS, FLV, RTMP and other video streaming protocols. The required parameters include: video streaming address, authentication information, video encoding format, frame rate and other parameters;
[0155] Step 1-1, parsing the video stream address: first parse the video stream address and extract the server address, port number and protocol type information;
[0156] Step 1-2, establish a network connection: according to the extracted information, try to establish a network connection with the video streaming server through the TCP protocol or the UDP protocol;
[0157] Step 1-3, send authentication information: If the video streaming server requires authentication, send authentication information to the server for verification after establishing the connection;
[0158] Step 1-4, negotiate transmission parameters: After the connection is established, the client and server need to negotiate transmission parameters;
[0159] Step 1-5, start video stream transmission: After parameter negotiation is completed, the server starts sending video stream data to the client, and the client receives and decodes the data;
[0160] Step 2: Video stream image acquisition:
[0161] With the progress of society and the development of science and technology, the clarity and resolution of videos have been continuously improved, which will generate a large amount of video data. In this method, the computer vision library OpenCV, a deep learning tool, is used to collect video frame images by using two methods: timed video frame image acquisition and automatic video key frame. Video image frame extraction reduces a large amount of video data and ensures that key images are preserved, which plays a key role in improving video detection accuracy and provides important data support for subsequent video image comparison and recognition.
[0162] Step 2-1, timed video frame image acquisition:
[0163] (1) Set the timer: First, set the time interval for image acquisition. The default value is 1 minute. Use the APScheduler library in Python to schedule and execute scheduled tasks. Set the timer to automatically capture video images according to the time interval for image acquisition.
[0164] (2) Capture video stream: After the timer is triggered, the system starts capturing the video stream;
[0165] (3) Extract image frames: From the captured video stream, use the OpenCV library read() function to capture image frames from the video stream according to the time interval set by the timer;
[0166] (4) Saving and processing: adjust all image frames to a uniform size, and use the cv2.imwrite() function of the computer vision library OpenCV to save the extracted image frames to a specified storage location such as (device number / year / month / day / image number) for subsequent analysis and processing. At the same time, the image frames can also be pre-processed as needed;
[0167] Step 2-2: Automatic video key frame image acquisition:
[0168] (1) Video preprocessing: Use the OpenCV library read() function to read individual frames from the video stream. The video frame rate defaults to 25fps to reduce the amount of calculation or adapt to specific analysis requirements. Use filters to reduce the noise of the video frames. The noise reduction method used uses mean filtering, Gaussian filtering and median filtering to reduce the noise of the video frames. The specific steps are as follows:
[0169] First, a smaller filter is selected by using mean filtering to perform preliminary smoothing on the video frame to remove part of the noise in order to balance the denoising effect and the retention of image details;
[0170] The mean filter smoothes the image by calculating the average value of the neighborhood around the pixel. It is suitable for removing mild noise. The formula is:
[0171] ;
[0172] Among them, Input(x,y) represents the pixel value at position (x,y) in the input image, Output(x,y) represents the pixel value at position (x,y) in the output image, n is the size of the filter, i and j represent the coordinates (i,j) of the pixel point in the surrounding area of (x,y), and the sum of the pixels in the surrounding area is calculated according to the value of the filter;
[0173] After the mean filter, a Gaussian filter is applied to select an appropriate Gaussian kernel size and standard deviation to ensure the denoising effect and preserve image details as much as possible, and the video frame is further smoothed to remove more noise;
[0174] The Gaussian filter uses Gaussian distribution to calculate the weights of pixels in the neighborhood, which is suitable for a greater degree of noise removal. The formula is:
[0175] ;
[0176] Where Input(x,y) represents the pixel value at position (x,y) in the input image, Output(x,y) represents the pixel value at position (x,y) in the output image, G(i,j) is the Gaussian distribution function, and the weight of the pixel coordinate position (i,j) in the image is the coordinate position of the input (x,y) coordinate.
[0177] Finally, the median filter is applied to remove impulse noise such as salt and pepper noise, which has a good effect. The final denoising process of the video frame can further improve the image quality.
[0178] The median filter sorts the pixel values in the neighborhood around the pixel and then takes the middle value as the output pixel value. The formula is:
[0179] ;
[0180] Among them, Input(x,y) represents the pixel value at position (x,y) in the input image, Output(x,y) represents the pixel value at position (x,y) in the output image, and median(Input(x,y),....,Input(x,y)) represents the median operation;
[0181] The comprehensive use of mean filtering, Gaussian filtering and median filtering methods can effectively remove various noises in the video frame, improve image quality, and provide more reliable input for subsequent feature extraction, processing and analysis tasks;
[0182] (2) Key frame prediction:
[0183] The key frame selection is performed by combining the three-frame difference method with the recurrent neural network. The three-frame difference method is used to capture the inter-frame differences between adjacent frames after video preprocessing to form three-frame differences. The three-frame difference map is used as the input of the recurrent neural network model. The cyclic structure of the recurrent neural network is used to capture the temporal dependency between frames, learn the dynamic changes between video frames, understand the evolution of video content, and improve the accuracy of key frame detection by combining timing information and inter-frame differences.
[0184] First, the difference images between the kth frame and the k-1th frame and the difference images between the k+1th frame and the kth frame are obtained respectively, and then the grayscale image is converted into a binary image. Finally, the obtained binary difference images are subjected to an “AND” operation to obtain three-frame difference images.
[0185] The formula is:
[0186] ;
[0187] Among them, G k (image) is the result image, P k (image) is the k-th frame image, P k-1 (image) is the k-1th frame image, P k+1 (image) is the k+1th frame image;
[0188] Then, a binary classification recurrent neural network model is designed. The output layer of the model uses the built-in sigmoid activation function of the recurrent neural network. The three-frame difference image is input to generate a probability value between 0 and 1. The default threshold T is set to 0.65. When the output probability value is greater than T, the output result is 1, and the current frame is a key frame. Otherwise, the output result is 0, and the current frame is a non-key frame. The three-frame difference method can detect moving targets more accurately because the choice of threshold directly affects the binarization result of the pixels in the differential image, which in turn affects the final moving target extraction. When the threshold is set too high, some useful changes in the image may be ignored; when it is set too low, part of the background may be mistaken for the foreground target. By setting the threshold T to 0.65 by default, it can not only ensure the recognition of image change differences, but also take into account the impact of part of the background on the change differences, and can be dynamically adjusted according to the needs of practical applications;
[0189] The formula is:
[0190] ;
[0191] Among them, t is the output of the recurrent neural network model, e is a natural constant, and T is the set threshold;
[0192] Step 3: Image acquisition and processing:
[0193] In order to reduce interference factors in the change detection process and ensure the accuracy and effectiveness of image change detection, this method grayscales and enhances the collected images to reduce the amount of data, improve image processing efficiency, highlight image details, and enhance image contrast. At the same time, it can also improve the adaptability to different application scenarios and needs.
[0194] Step 3-1: Image grayscale processing:
[0195] Image grayscale processing is to convert a color image into a grayscale image. Its purpose is to convert the image from three channels to a single channel to simplify the image processing task and reduce the amount of calculation. This method uses the fusion method of the maximum value method and the weighted average value to traverse the pixels in the original image and perform grayscale processing respectively. By using the fusion method of the maximum value method and the weighted average value, the pixels in the original image are traversed and grayscaled respectively. The fusion method of the maximum value method and the weighted average value is used to retain the image details and contrast in the grayscale process, reduce color deviation, and improve the adaptability and robustness of the grayscale method. The formula is:
[0196] ;
[0197] Among them, R, G, B are the corresponding value ranges [0,255] in the RGB model, and T is the weight of the maximum value method;
[0198] Step 3-2, image enhancement:
[0199] The grayscale image after grayscale processing is subjected to image equalization transformation based on the histogram equalization method to achieve image enhancement. The histogram equalization method realizes nonlinear stretching of the image by widening the grayscale with a large number of pixels in the image and reducing the grayscale with a small number of pixels, and redistributes the image pixel values so that the number of pixels within a certain grayscale range is roughly the same. It can effectively suppress background noise, reduce image blur and quality degradation caused by background elements, and significantly enhance the contrast of the image, making the grayscale level more obvious and the details clearer, which is helpful for subsequent comparison and analysis of image content;
[0200] The specific steps are as follows:
[0201] (1) The grayscale value of the image to be processed at each level of the input image is in the range of [0, L-1], and the value of the corresponding position is obtained after equalization;
[0202] The formula is: L=2 b ;
[0203] Where L is the grayscale level of the image, and b is the number of image bits;
[0204] ;
[0205] Among them, r j is the gray value of the input image, s is the gray value after equalization, j is the gray value pixel, k is the total number of gray value pixels, and T() is the histogram equalization conversion;
[0206] (2) Calculate the probability of occurrence of each class gray value:
[0207] The formula is:
[0208] ;
[0209] Where sum(s) is the number of pixels with grayscale value s in the image, and M and N represent the number of rows and columns of the image, respectively;
[0210] (3) The gray level cumulative distribution function of each probability is used to calculate the cumulative probability of each class gray value.
[0211] The formula is:
[0212] ;
[0213] Among them, r k is the gray level value of the image, p(r j ) is the probability of occurrence of the class gray value in the original image, and j is a temporary variable. The sum of k is calculated in turn. CDF(r k ) is gray level less than or equal to r k The cumulative probability of the pixel;
[0214] (4) Perform image equalization transformation on the gray level of each probability;
[0215] The formula is:
[0216] ;
[0217] Among them, T(r k ) corresponds to the gray level r k The pixel value after equalization, L is the number of gray levels of the image;
[0218] For example, a 3-bit image (L=8) with a size of 30×20 pixels has a grayscale range of integers [0,L-1]=[0,7], and the grayscale distribution table is shown in the following table;
[0219] ;
[0220] The above method is used to calculate:
[0221] ;
[0222] The same goes for the rest. Calculate all s by analogy. k The value is rounded to the nearest integer and the result is:
[0223] ;
[0224] According to the calculation results, the image after equalization has only 6 gray levels. Because no new gray levels are generated after the image equalization transformation, the gray level range of the image after equalization is wider, which effectively enhances the contrast of the image.
[0225] Step 4: Change detection configuration:
[0226] In video image change detection, detection area selection and detection target filtering are performed by configuring detection area and whitelist targets. Through change detection configuration, some pre-set detection areas or targets can be marked as "whitelist" according to specific scenarios and needs. When performing change detection, only detection areas and non-whitelist targets can be detected, thereby filtering out non-detection areas and whitelist targets, improving detection accuracy, flexibility and reliability;
[0227] Step 4-1, Change detection configuration:
[0228] Through the detection area configuration, you can perform video designated area detection, minimum detection area and sensitivity settings. The designated area defaults to the entire area. The larger the sensitivity value, the higher the sensitivity. The value range is [0,100] and the default value is 100. In reality, parameterized configuration can be performed according to different application scenarios.
[0229] The steps for specifying area detection are as follows:
[0230] First, the user selects and sets the video stream through the Web application, and uses the cap.read() function in OpenCV to read the video image from the video stream;
[0231] Then, use the cv2.imshow() function in OpenCV to display the video image;
[0232] Finally, according to user needs, use the function cv2.rectangle() in OpenCV to draw the detection area on the video image with the mouse, and save the pixel coordinates of the user-selected video detection area to (X, Y, W, H), where X is the starting horizontal coordinate, Y is the starting vertical coordinate, W is the area width, and H is the area height;
[0233] Step 4-2, Whitelist target training:
[0234] The whitelist target training uses the YOLOv9 target detection model. According to the user's actual application scenario, you can upload a set of images that meet the standards through the Web application and perform a custom data set training model to filter the whitelist targets in the process of video image change detection in the user's actual application. The specific steps are as follows:
[0235] List target training includes the following steps:
[0236] (1) Data upload: Users select and upload data sets and model names that meet the specified format, quantity, and quality standards through the web application according to actual needs;
[0237] (2) Data preprocessing and labeling: The uploaded images are resized, normalized, and labeled with target objects. By integrating the Grounding DINO target detection algorithm, the image sets uploaded by users are automatically processed and labeled. After automatic processing, a manual review interface is provided to correct incorrect annotations. After manual review, the data set is automatically divided into training set, validation set, and test set in a ratio of 7:2:1.
[0238] (3) Model training: By reading the training set information uploaded by the user, the model parameters are automatically adjusted according to the characteristics of the data set, and the YOLOv9 configuration file is dynamically generated, including the training set path, model configuration file, and hyperparameters. After the training is completed, the evaluation script is automatically called to evaluate the trained model and the evaluation results are recorded in the training log;
[0239] (4) Model generation: After the training is completed, the model weight file in the weights format obtained through training is automatically saved and added to the user whitelist model library for subsequent video association;
[0240] (5) Model intelligent learning: When collecting video images, select a training model, perform target detection to identify the target object in the video, record its location information and category information, and extract the corresponding target image as a new training sample. Use artificial intelligence technology to automatically identify the changes in the accuracy, recall rate and mAP indicators of the model algorithm to make intelligent decisions. Use the reinforcement learning algorithm to automatically decide whether to trigger model updates. Use active learning strategies to select the most informative samples for model updates. Use transfer learning and domain adaptation technologies to enhance the generalization ability and adaptability of the model. At the same time, through real-time monitoring and real-time update mechanisms, timely trigger model updates to respond to environmental changes, realize intelligent model optimization and improve algorithms to actively select the most informative samples for model updates.
[0241] Through change detection configuration, users can set detection areas and whitelist target filtering according to their needs, and implement intelligent whitelist model update and optimization processes to improve the performance and adaptability of the model and better adapt to changing environments and scenarios;
[0242] Step 5: Detection area selection:
[0243] For the collected and processed video frame images, the adjacent frame images are compared by the structural similarity index method and the image feature extraction and vectorization comparison method for change detection, which can improve the accuracy, robustness and adaptability of image comparison, effectively detect the change area recognition in the image, and thus more effectively cope with the change detection in various complex scenes;
[0244] Step 5-1: According to the detection area pixel coordinates (X, Y, W, H) configured for the detection area in the detection video, the detection area pixel value of the image is calculated. The formula is as follows:
[0245] ;
[0246] Where x0 is the horizontal pixel coordinate, y0 is the vertical pixel coordinate, W is the region width, and H is the region height;
[0247] For example, the image pixel is I, its size is 5×5, and the pixel values are as follows:
[0248] ;
[0249] The coordinates of the area to be detected are (1,1,3,2). According to the formula, the pixel value of the detection area is:
[0250] ;
[0251] Step 5-2, Whitelist target filtering:
[0252] Based on the model library obtained by whitelist target training, the whitelist targets in the collected images are identified based on the YOLOv9 algorithm to obtain the target matching degree and the target area. The specific process is as follows:
[0253] (1) Load the pre-trained whitelist target model;
[0254] (2) Input the video image to be detected, use the model.predict() function in the YOLOv9 algorithm to perform target detection on the input image, identify various targets in the image and output target information;
[0255] (3) Use the pre-trained neural network model to extract the feature vector of each detected target;
[0256] (4) Calculate the cosine similarity between the feature vector of the target and the feature vector of the target in the target library. The cosine similarity indicates that the two vectors are closer in direction, that is, the matching degree is higher. When the cosine similarity is greater than 0.75, it is identified as a whitelist target. The cosine similarity calculation formula is:
[0257] ;
[0258] Among them, v1 and v2 are the feature vector of the target and the feature vector of the target in the target library respectively, and ||v|| represents the norm of vector v;
[0259] (5) Filter out targets with cosine similarity greater than 0.75 and determine them as whitelist targets. Use the get_bbox(obj) function to obtain the bounding box coordinates, width, and height of the target, and return the data in the format of (x, y, w, h);
[0260] (6) According to the obtained whitelist target pixel coordinates (x, y, w, h), each pixel (i, j) in the selected detection area is checked to see if it is in the whitelist target area. If it is to be excluded from the selected detection area, the formula is as follows:
[0261] ;
[0262] Where (i, j) is the image pixel region, x is the horizontal pixel coordinate, y is the vertical pixel coordinate, w is the region width, and h is the region height;
[0263] Based on the selection of the detection area, whitelist target filtering is performed to finally obtain the area that needs to be detected for changes;
[0264] Step 6: Image change detection:
[0265] Step 6-1: Image structure similarity comparison:
[0266] The calculation of the structural similarity index is based on brightness, contrast and structure. First, the original image and the reference image are divided into small blocks of the same size. Then, for each small block, the similarity of its brightness, contrast and structure is calculated respectively. The brightness similarity is calculated using the mean and variance of the brightness, and the contrast similarity is calculated using the mean and variance of the contrast. The structural similarity is obtained by calculating the covariance between the original image and the reference image and the variance of the two. Then, the similarity of each small block is weighted averaged to obtain the similarity of the entire image. The value range of the structural similarity index S1 is [-1,1], where 1 means that the two images are exactly the same, and -1 means that the two images are completely different. The closer the value is to 1, the higher the structural similarity of the two images, and the closer the value is to -1, the lower the structural similarity.
[0267] The formula is:
[0268] ;
[0269] Among them, x and y are the two images detected, μ x and μ y is the mean of x and y, is the variance of x and y, σ xy is the covariance of images x and y;
[0270] Step 6-2: Image feature extraction and matching:
[0271] The deep learning-based artificial intelligence model, ResNet deep convolutional neural network, is used to extract and match the features of the original image and the reference image. The specific steps include:
[0272] (1) For the processed input image, use the preprocess_imag() function to preprocess the image, then use the features method of the model to extract the feature map and output the feature map array;
[0273] (2) Set the ResNet model to evaluation mode using the model.eval() function;
[0274] (3) Use the model’s feature() method to extract feature vectors and convert feature vector arrays;
[0275] Using cosine similarity, the vector similarity S2 is calculated for the feature vector arrays extracted from the original image and the reference image. The value range of S2 is [-1,1], where 1 means that the two images are exactly the same, and -1 means that the two images are completely different. The closer the value is to 1, the higher the structural similarity of the two images; the closer the value is to -1, the lower the structural similarity;
[0276] The formula is:
[0277] ;
[0278] Among them, x and y are the feature image arrays for detecting two images, ∙ represents the dot product of the vectors, and ||x|| and ||y|| are the norms of vectors x and y respectively;
[0279] Step 6-3, calculate the comprehensive similarity:
[0280] By setting the fusion weight α, the default value of which is 0.75, the image structure similarity S1 and the feature vector similarity S2 are calculated by setting the weight α;
[0281] The formula is:
[0282] ;
[0283] Among them, α is the fusion weight, S1 is the structural similarity, and S2 is the feature vector similarity;
[0284] This method can combine the image comparison capability of image structure similarity comparison and the feature extraction capability of artificial intelligence models to improve the accuracy and comprehensiveness of information on detected changed areas;
[0285] Step 6-4, determine and save the changed area:
[0286] According to the above steps, the comprehensive similarity S is obtained and the changed area is selected. When the comprehensive similarity S is less than 0.5, the area is determined to be a changed area;
[0287] The formula is:
[0288] ;
[0289] Among them, S is the comprehensive similarity, O is the changed area when the value is 1, and the non-changed area when it is 0;
[0290] When it is determined to be a changed area, first use the function cv2.boundingRect() in OpenCV to obtain the coordinates of the changed area (x1, y1, w1, h1), then use the function cv2.rectangle() in OpenCV to draw a rectangular bounding box on the original image, and use the function cv2.imwrite() in OpenCV to generate the annotated image. Finally, the original image, the changed image, the annotated image, the change time interval, the pixel area of the changed area, the pixel coordinates of the changed area, the comprehensive recognition and other information are stored in the database;
[0291] Step 7: Detection change information notification:
[0292] When abnormal or important changes are detected in the video image, the original image, the changed image, the annotated image, the change time interval, the pixel area of the changed area, the pixel coordinates of the changed area and the comprehensive recognition degree are set according to the specific business scenario, so as to send accurate notifications when changes are detected. It supports multiple notification methods such as email, SMS, phone and instant messaging, which can timely detect abnormal or important changes in the video, respond quickly, improve efficiency and reduce risks;
[0293] Step 8: Record and analyze test information:
[0294] When abnormal or important changes are detected in the video image, the change log record will be stored, and the log record will be combined with the artificial intelligence model, the output results of the artificial intelligence model will be integrated into the log system, and the intelligent perception results will be integrated with the traditional log data to form a complete log record data set; machine learning and data mining technology will be used to intelligently analyze the log data, perform anomaly detection analysis, extract key features and conduct in-depth analysis. It also provides an interactive visualization interface to support users to customize the viewing and analysis of data according to their needs, and display the intelligent analysis results in the form of charts, dashboards, etc., so that users can intuitively understand and analyze.
[0295] The main functions achieved by the present invention are: using the above-mentioned video image change detection method, users can configure the detection area and whitelist targets according to specific needs, use multiple fusion methods for change detection, and customize the message notification template and notification method, so as to achieve personalized monitoring needs. At the same time, using artificial intelligence technology to perform intelligent perception and analysis of monitoring videos can improve the intelligence level of the monitoring system, automatically discover abnormal situations and make timely notifications, greatly improving the efficiency and reliability of the monitoring system.
[0296] The video image change detection method based on artificial intelligence of the present invention has common mechanical installation methods, connection methods or setting methods, which can be implemented as long as they can achieve their beneficial effects; the OpenCV, YOLOv9 target detection model, Grounding DINO target detection algorithm and YOLOv9 algorithm are all open source data, and technicians in the industry only need to install and operate them according to the accompanying instruction manuals, without the need for creative labor by technicians in this field.
[0297] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A video image change detection method based on artificial intelligence, characterized in that: The following steps are involved: Step 1: Establish a connection with the video streaming server: Step 1-1, parsing the video stream address: first parse the video stream address and extract the server address, port number and protocol type information; Step 1-2, establish a network connection: according to the extracted information, try to establish a network connection with the video streaming server through the TCP protocol or the UDP protocol; Step 1-3, send authentication information: If the video streaming server requires authentication, send authentication information to the server for verification after establishing the connection; Step 1-4, negotiate transmission parameters: After the connection is established, the client and server need to negotiate transmission parameters; Step 1-5, start video stream transmission: After parameter negotiation is completed, the server starts sending video stream data to the client, and the client receives and decodes the data; Step 2: Video stream image acquisition: Step 2-1, timed video frame image acquisition: (1) Set the timer: First, set the time interval for image acquisition. The default value is 1 minute. Use the APScheduler library in Python to schedule and execute scheduled tasks. Set the timer to automatically capture video images according to the time interval for image acquisition. (2) Capture video stream: After the timer is triggered, the system starts capturing the video stream; (3) Extract image frames: From the captured video stream, use the OpenCV library read() function to capture image frames from the video stream according to the time interval set by the timer; (4) Saving and processing: adjust all image frames to a uniform size, and use the cv2.imwrite() function of the computer vision library OpenCV to save the extracted image frames to a specified storage location for subsequent analysis and processing. At the same time, the image frames can also be pre-processed as needed; Step 2-2: Automatic video key frame image acquisition: (1) Video preprocessing: Use the OpenCV library read() function to read individual frames from the video stream. The video frame rate defaults to 25fps to reduce the amount of calculation or adapt to specific analysis requirements. Use filters to reduce the noise of the video frames. The noise reduction methods used use mean filtering, Gaussian filtering, and median filtering to reduce the noise of the video frames. (2) Key frame prediction: The key frame selection is performed by combining the three-frame difference method with the recurrent neural network. The three-frame difference method is used to capture the inter-frame differences between adjacent frames after video preprocessing to form three-frame differences. The three-frame difference map is used as the input of the recurrent neural network model. The cyclic structure of the recurrent neural network is used to capture the temporal dependency between frames, learn the dynamic changes between video frames, understand the evolution of video content, and improve the accuracy of key frame detection by combining timing information and inter-frame differences. Step 3: Image acquisition and processing: Step 3-1: Image grayscale processing: Image grayscale processing is to convert a color image into a grayscale image. Its purpose is to convert the image from three channels to a single channel to simplify the image processing task and reduce the amount of calculation. This method uses the fusion method of the maximum value method and the weighted average value to traverse the pixels in the original image and perform grayscale processing respectively. By using the fusion method of the maximum value method and the weighted average value, the pixels in the original image are traversed and grayscaled respectively. The fusion method of the maximum value method and the weighted average value is used to retain the image details and contrast in the grayscale process, reduce color deviation, and improve the adaptability and robustness of the grayscale method. The formula is: ; Among them, R, G, B are the corresponding value ranges [0,255] in the RGB model, and T is the weight of the maximum value method; Step 3-2, image enhancement: The grayscale image after grayscale processing is subjected to image equalization transformation based on the histogram equalization method to achieve image enhancement. The histogram equalization method realizes nonlinear stretching of the image by widening the grayscale with a large number of pixels in the image and reducing the grayscale with a small number of pixels, and redistributes the image pixel values so that the number of pixels within a certain grayscale range is roughly the same. It can effectively suppress background noise, reduce image blur and quality degradation caused by background elements, and significantly enhance the contrast of the image, making the grayscale level more obvious and the details clearer, which is helpful for subsequent comparison and analysis of image content; Step 4: Change detection configuration: Step 4-1, Change detection configuration: Through the detection area configuration, you can perform video designated area detection, minimum detection area and sensitivity settings. The designated area defaults to the entire area. The larger the sensitivity value, the higher the sensitivity. The value range is [0,100] and the default is 100. Step 4-2, Whitelist target training: Whitelist target training uses the YOLOv9 target detection model. Based on the user's actual application scenario, you can upload a set of images that meet the standards through the Web application and perform a custom data set training model to filter whitelist targets in the process of video image change detection based on the user's actual application; Step 5: Detection area selection: Step 5-1: According to the detection area pixel coordinates (X, Y, W, H) configured for the detection area in the detection video, the detection area pixel value of the image is calculated. The formula is as follows: ; Where x0 is the horizontal pixel coordinate, y0 is the vertical pixel coordinate, W is the region width, and H is the region height; Step 5-2, Whitelist target filtering: Based on the model library obtained by whitelist target training, the whitelist targets in the collected images are identified based on the YOLOv9 algorithm to obtain the target matching degree and the target area; Step 6: Image change detection: Step 6-1: Image structure similarity comparison: The calculation of the structural similarity index is based on brightness, contrast and structure. First, the original image and the reference image are divided into small blocks of the same size. Then, for each small block, the similarity of its brightness, contrast and structure is calculated respectively. The brightness similarity is calculated using the mean and variance of the brightness, and the contrast similarity is calculated using the mean and variance of the contrast. The structural similarity is obtained by calculating the covariance between the original image and the reference image and the variance of the two. Then, the similarity of each small block is weighted averaged to obtain the similarity of the entire image. The value range of the structural similarity index S1 is [-1,1], where 1 means that the two images are exactly the same, and -1 means that the two images are completely different. The closer the value is to 1, the higher the structural similarity of the two images, and the closer the value is to -1, the lower the structural similarity. The formula is: ; Among them, x and y are the two images detected, μ x and μ y is the mean of x and y, is the variance of x and y, σ xy is the covariance of images x and y; Step 6-2: Image feature extraction and matching: Use the deep learning-based artificial intelligence model, ResNet deep convolutional neural network, to extract and match the features of the original image and the reference image; Step 6-3, calculate the comprehensive similarity: By setting the fusion weight α, the default value of which is 0.75, the image structure similarity S1 and the feature vector similarity S2 are calculated by setting the weight α; The formula is: ; Among them, α is the fusion weight, S1 is the structural similarity, and S2 is the feature vector similarity; This method can combine the image comparison capability of image structure similarity comparison and the feature extraction capability of artificial intelligence models to improve the accuracy and comprehensiveness of information on detected changed areas; Step 6-4: Determine and save the changed area: According to the above steps, the comprehensive similarity S is obtained, and the changed area is selected. When the comprehensive similarity S is less than 0.5, the area is determined to be a changed area; The formula is: ; Among them, S is the comprehensive similarity, O is the changed area when the value is 1, and the non-changed area when it is 0; When it is determined to be a changed area, first use the function cv2.boundingRect() in OpenCV to obtain the coordinates of the changed area (x1, y1, w1, h1), then use the function cv2.rectangle() in OpenCV to draw a rectangular bounding box on the original image, and use the function cv2.imwrite() in OpenCV to generate the annotated image after annotation. Finally, the original image, the changed image, the annotated image, the change time interval, the pixel area of the changed area, the pixel coordinates of the changed area and the comprehensive recognition information are stored in the database; Step 7: Detection change information notification: When abnormal or important changes are detected in the video image, the original image, the changed image, the annotated image, the change time interval, the pixel area of the changed area, the pixel coordinates of the changed area and the comprehensive recognition degree are set according to the specific business scenario, so as to send accurate notifications when changes are detected. It supports multiple notification methods such as email, SMS, phone and instant messaging, which can timely detect abnormal or important changes in the video, respond quickly, improve efficiency and reduce risks; Step 8: Record and analyze test information: When abnormal or important changes are detected in the image in the video, the change log records will be stored and combined with the artificial intelligence model, the output results of the artificial intelligence model will be integrated into the log system, and the intelligent perception results will be integrated with traditional log data to form a complete log record data set; machine learning and data mining techniques will be used to perform intelligent analysis of log data, perform anomaly detection analysis, extract key features and conduct in-depth analysis, and provide an interactive visualization interface to support users to customize viewing and analysis of data according to their needs, and display the intelligent analysis results in the form of charts and dashboards for users to intuitively understand and analyze.
2. The video image change detection method based on artificial intelligence as claimed in claim 1, characterized in that: The specific steps of the noise reduction method using mean filtering, Gaussian filtering and median filtering to perform video frame noise reduction are as follows: First, a smaller filter is selected by using mean filtering to perform preliminary smoothing on the video frame to remove part of the noise in order to balance the denoising effect and the retention of image details; The mean filter smoothes the image by calculating the average value of the neighborhood around the pixel. It is suitable for removing mild noise. The formula is: ; Among them, Input(x,y) represents the pixel value at position (x,y) in the input image, Output(x,y) represents the pixel value at position (x,y) in the output image, n is the size of the filter, i and j represent the coordinates (i,j) of the pixel point in the surrounding area of (x,y), and the sum of the pixels in the surrounding area is calculated according to the value of the filter; After the mean filter, a Gaussian filter is applied to select an appropriate Gaussian kernel size and standard deviation to ensure the denoising effect and preserve image details as much as possible, and the video frame is further smoothed to remove more noise; The Gaussian filter uses Gaussian distribution to calculate the weights of pixels in the neighborhood, which is suitable for a greater degree of noise removal. The formula is: ; Where Input(x,y) represents the pixel value at position (x,y) in the input image, Output(x,y) represents the pixel value at position (x,y) in the output image, G(i,j) is the Gaussian distribution function, and the weight of the pixel coordinate position (i,j) in the image is the coordinate position of the input (x,y) coordinate. Finally, the median filter is applied to remove salt and pepper noise, which has a good effect. The final denoising process of the video frame can further improve the image quality. The median filter sorts the pixel values in the neighborhood around the pixel and then takes the middle value as the output pixel value. The formula is: ; Among them, Input(x,y) represents the pixel value at position (x,y) in the input image, Output(x,y) represents the pixel value at position (x,y) in the output image, and median(Input(x,y),....,Input(x,y)) represents the median operation; The combined use of mean filtering, Gaussian filtering and median filtering methods can effectively remove various noises in video frames, improve image quality, and provide more reliable input for subsequent feature extraction, processing and analysis tasks.
3. The video image change detection method based on artificial intelligence as claimed in claim 1, characterized in that: The key frame prediction comprises the following steps: First, the difference images between the kth frame and the k-1th frame and the difference images between the k+1th frame and the kth frame are obtained respectively, and then the grayscale image is converted into a binary image. Finally, the obtained binary difference images are subjected to an "AND" operation to obtain three-frame difference images. The formula is: ; Among them, G k (image) is the result image, P k (image) is the k-th frame image, P k-1 (image) is the k-1th frame image, P k+1 (image) is the k+1th frame image; Then, a binary classification recurrent neural network model is designed. The output layer of the model uses the built-in sigmoid activation function of the recurrent neural network. The difference map between three frames is input to generate a probability value between 0 and 1. The default threshold T is set to 0.
65. When the output probability value is greater than T, the output result is 1, and the current frame is a key frame. Otherwise, the output result is 0, and the current frame is a non-key frame. The formula is: ; Among them, t is the output of the recurrent neural network model, e is a natural constant, and T is the set threshold; By setting the threshold T to 0.65 by default, it is possible to ensure the recognition of image change differences while taking into account the influence of some backgrounds on the change differences, and it can be dynamically adjusted according to the needs of practical applications.
4. The method for detecting video image changes based on artificial intelligence as claimed in claim 3, characterized in that: The default threshold T is set to 0.65 based on the following reasons: The three-frame difference method can detect moving targets more accurately because the choice of threshold directly affects the binarization result of pixels in the difference image, which in turn affects the final extraction of moving targets. When the threshold is set too high, some useful changes in the image may be ignored; and when it is set too low, part of the background may be mistaken for a foreground target.
5. The method for detecting video image changes based on artificial intelligence as claimed in claim 1, characterized in that: The default weight T of the maximum value method for image grayscale processing is 0.6, and the value range is [0,1].
6. The method for detecting video image changes based on artificial intelligence as claimed in claim 1, characterized in that: The image enhancement comprises the following steps: (1) The grayscale value of the image to be processed at each level of the input image is in the range of [0, L-1], and the value of the corresponding position is obtained after equalization; The formula is: L=2 b ; Where L is the grayscale level of the image, and b is the number of image bits; ; Among them, r j is the gray value of the input image, s is the gray value after equalization, j is the gray value pixel, k is the total number of gray value pixels, and T() is the histogram equalization conversion; (2) Calculate the probability of occurrence of each class gray value: The formula is: ; Where sum(s) is the number of pixels with grayscale value s in the image, and M and N represent the number of rows and columns of the image, respectively; (3) The gray level cumulative distribution function of each probability is used to calculate the cumulative probability of each class gray value. The formula is: ; Among them, r k is the gray level value of the image, p(r j ) is the probability of occurrence of the class gray value in the original image, and j is a temporary variable. The sum of k is calculated in turn. CDF(r k ) is gray level less than or equal to r k The cumulative probability of the pixel; (4) Perform image equalization transformation on the gray level of each probability; The formula is: ; Among them, T(r k ) corresponds to the gray level r k The pixel value after equalization, L is the number of gray levels of the image.
7. The method for detecting video image changes based on artificial intelligence as claimed in claim 1, characterized in that: The designated area detection steps: First, the user selects and sets the video stream through the Web application, and uses the cap.read() function in OpenCV to read the video image from the video stream; Then, use the cv2.imshow() function in OpenCV to display the video image; Finally, according to user needs, use the cv2.rectangle() function in OpenCV to draw the detection area on the video image with the mouse, and save the pixel coordinates of the user-selected video detection area in (X, Y, W, H), where X is the starting horizontal coordinate, Y is the starting vertical coordinate, W is the area width, and H is the area height.
8. The video image change detection method based on artificial intelligence as claimed in claim 1, characterized in that: The whitelist target training comprises the following steps: (1) Data upload: Users select and upload data sets and model names that meet the specified format, quantity, and quality standards through the web application according to actual needs; (2) Data preprocessing and labeling: The uploaded images are resized, normalized, and labeled with target objects. By integrating the Grounding DINO target detection algorithm, the image sets uploaded by users are automatically processed and labeled. After automatic processing, a manual review interface is provided to correct incorrect annotations. After manual review, the data set is automatically divided into training set, validation set, and test set in a ratio of 7:2:
1. (3) Model training: By reading the training set information uploaded by the user, the model parameters are automatically adjusted according to the characteristics of the data set, and the YOLOv9 configuration file is dynamically generated, including the training set path, model configuration file, and hyperparameters. After the training is completed, the evaluation script is automatically called to evaluate the trained model and the evaluation results are recorded in the training log; (4) Model generation: After the training is completed, the model weight file in the weights format obtained through training is automatically saved and added to the user whitelist model library for subsequent video association; (5) Model intelligent learning: When collecting video images, select a training model, perform target detection to identify the target object in the video, record its location information and category information, and extract the corresponding target image as a new training sample. Use artificial intelligence technology to automatically identify the changes in the accuracy, recall rate and mAP indicators of the model algorithm to make intelligent decisions. Use the reinforcement learning algorithm to automatically decide whether to trigger model updates. Use active learning strategies to select the most informative samples for model updates. Use transfer learning and domain adaptation technologies to enhance the generalization ability and adaptability of the model. At the same time, through real-time monitoring and real-time update mechanisms, timely trigger model updates to respond to environmental changes, realize intelligent model optimization and improve algorithms to actively select the most informative samples for model updates. Through change detection configuration, users can set detection areas and whitelist target filtering according to their needs, and implement intelligent whitelist model update and optimization processes to improve the performance and adaptability of the model and better adapt to changing environments and scenarios.
9. The method for detecting video image changes based on artificial intelligence as claimed in claim 1, characterized in that: The whitelist target filtering includes the following steps: (1) Load the pre-trained whitelist target model; (2) Input the video image to be detected, use the model.predict() function in the YOLOv9 algorithm to perform target detection on the input image, identify various targets in the image and output target information; (3) Use the pre-trained neural network model to extract the feature vector of each detected target; (4) Calculate the cosine similarity between the feature vector of the target and the feature vector of the target in the target library. The cosine similarity indicates that the two vectors are closer in direction, that is, the matching degree is higher. When the cosine similarity is greater than 0.75, it is identified as a whitelist target. The cosine similarity calculation formula is: ; Among them, v1 and v2 are the feature vector of the target and the feature vector of the target in the target library respectively, and ||v|| represents the norm of vector v; (5) Filter out targets with cosine similarity greater than 0.75 and determine them as whitelist targets. Use the get_bbox(obj) function to obtain the bounding box coordinates, width, and height of the target, and return the data in the format of (x, y, w, h); (6) According to the obtained whitelist target pixel coordinates (x, y, w, h), each pixel (i, j) in the selected detection area is checked to see if it is in the whitelist target area. If it is to be excluded from the selected detection area, the formula is as follows: ; Where (i, j) is the image pixel region, x is the horizontal pixel coordinate, y is the vertical pixel coordinate, w is the region width, and h is the region height; Based on the selection of the detection area, whitelist target filtering is performed to finally obtain the area that needs to be detected for changes.
10. The method for detecting video image changes based on artificial intelligence according to claim 1, characterized in that: The extraction and matching of the original image and the reference image features comprises the following steps: (1) For the processed input image, use the preprocess_imag() function to preprocess the image, then use the features method of the model to extract the feature map and output the feature map array; (2) Set the ResNet model to evaluation mode using the model.eval() function; (3) Use the model’s feature() method to extract feature vectors and convert feature vector arrays; Using cosine similarity, the vector similarity S2 is calculated for the feature vector arrays extracted from the original image and the reference image. The value range of S2 is [-1,1], where 1 means that the two images are exactly the same, and -1 means that the two images are completely different. The closer the value is to 1, the higher the structural similarity of the two images; the closer the value is to -1, the lower the structural similarity; The formula is: ; Among them, x and y are the feature image arrays for detecting two images, ∙ represents the dot product of the vectors, and ||x|| and ||y|| are the norms of vectors x and y, respectively.
