1. 跟踪特定颜色的对象
颜色信息对光照条件敏感,这里假设图像已经消除光照影响。
HSV色调饱和度值
色调:色谱
饱和度:特定颜色的强度,值是该像素的亮度
int main(int argc, char* argv[])
{
//Variable declarations and initatializations
// Iterate until the user presses the Esc key
while(true)
{
// Initialize the output image before each iteration
outputImage = Scalar(0, 0, 0);
// Capture the current frame
cap >> frame;
// Check if 'frame' is empty
if(frame.empty())
break;
// Resieze the frame
resize(frame, frame, Size(), scalingFactor, scalingFactor, INTER_AREA)
// Convert to HSV colorspace
cvtColor(frame, hsvImage, COLOR_BGR2HSV);
// Define the range of "blue" color in HSV colorspace
Scalar lowerLimit = Scalar(60, 100, 100);
Scalar upperLimit = Scalar(180, 255, 255);
// Threshold the HSV image to get only blue color
inRange(hsvImage, lowerLimit, upperLimit, mask);
// Computer bitwise-AND of input image and mask
bitwise_and(frame, frame, outputImage, mask=mask);
// Run median filter on the output to smoothen it
medianBlur(outputImage, outputImage, 5);
// Display the input and output image
imshow("Input", frame);
imshow("Output", outputImage);
// Get the keyboard input and check if it's 'Esc'
// 27 -> wait for 30ms
// 27 -> ASCII value of 'Esc' key
ch = waitKey(30);
if(ch == 27)
{
break;
}
}
return -1;
}
2. 构建交互式对象跟踪器
连续自适应平移算法CAMShift,改进版的meanshift算法.