Camshift algorithm, OpenCV implementation 1 - Back Projection

xiaoxiao2021-03-06  83

Camshift algorithm, "Continuously Apative Mean-Shift" algorithm is a motion tracking algorithm. It mainly reaches the purpose of tracking of the color information of the moving object in the video image. I decomposed this algorithm into three parts, for understanding: 1) Back Projection calculation 2) Mean Shift Algorithm 3) The Camshift Algorithm This mainly discusses the Back Projection here, and continues to discuss two algorithms in subsequent articles. The step of BACK Projection calculates the step of Back Projection is: 1. Calculate the color histogram of the trace target. In various color spaces, only H components in HSI space (or color space similar to HSI) can represent color information. Therefore, during the specific calculation process, the value of other color space is first transformed into the HSI space, and then the H component is calculated by 1D histogram. 2. Transform the original image into a color probability distribution image based on the colors of the colors, which is called "Back Projection". In the histogram function in OpenCV, the function of the Back Projection is: Void CvcalcBackProject (iPlimage ** img, cvarr ** backproject, const cvhistogram * hist); three parameters pass to this function: 1. IPlimage ** IMG: Store the original image, input. 2. Cvarr ** backproject: Store the Back Projection result, output. 3. CVHistogram * Hist: Store the straightcomer map, give the OpenCV code for calculating the Back Projection below.

1. Prepare a picture containing only trace targets, transform color space to HSI space, get H component: iPlimage * target = CVLoadImage ("target.bmp", - 1); // Load picture iPlimage * target_hsv = cvCreateImage (cvGetSize (target), IPL_DEPTH_8U, 3); IplImage * target_hue = cvCreateImage (cvGetSize (target), IPL_DEPTH_8U, 3); cvCvtColor (target, target_hsv, CV_BGR2HSV); // transformed to HSV space cvSplit (target_hsv, target_hue, NULL, NULL, NULL); // Get h component 2. Calculate the histogram of the H component, 1D histogram: iplimage * h_plane = cvcreateImage (cvgettsize (target_hsv), IPL_Depth_8u, 1); int hist_size [] = {255} // quantify the value of the h component to [0,255] float * ranges [] = {{0,360}}; // h component range of value [0,360) Cvhistogram * Hist = CvcreateHist (1, hist_size, ranges, 1 Cvcalchist (& Target_hue, HIST, 0, NULL); The problem of the value of the H component is required here, and the value of the H component is [0, 360), and the value range of this range cannot be represented by one byte. In order to be represented by a BYTE, you need to properly quantify the H value, where we quantify the range of H components to [0,255] .4. Calculate Back Projection: IPLIMAGE * RAWIMAGE; / / ------- --------------------------------------- // Get from Video frame, unsigned byte, one Channel // -------------------------------------------------- iPlimage * Result = CVCReateImage (C Vgetsize (Rawimage), IPL_Depth_8u, 1); CvcalcBackProject (& Rawimage, Result, HIST); 5. Result: Result is what we need. Algorithm analysis is a histogram of Target Image Tone (HUE) in CvCalcBackProject. The histogram can be seen as a probability distribution map. Before processing, the value of each of the target images describes the color information at this point, and after processing, the value of each pixel in the image becomes the possibility of this color information. A discrete metric, the possibility of appearing, the value of the pixel is large, and it is small. This provides a clue for the latter matching and tracking. ----------------------------- Committed to multimedia technology, becoming ideological software engineers ---------- -------------- This article is my original creation, to reprint, please contact me or indicate. Welcome everyone to make valuable comments on the content of the article, and I hope that everyone will point out the mistakes in the text, so I can correct it in time.

转载请注明原文地址:https://www.9cbs.com/read-93526.html

New Post(0)