gpt4 book ai didi

c++ - 仅绘制存在于多个帧上的轮廓以消除闪烁

转载 作者:搜寻专家 更新时间:2023-10-31 01:42:49 25 4
gpt4 key购买 nike

我已经在这里和网络的其余部分进行了一个多星期的研究,但无法得出任何结论。

我在 Linux 上使用 C++ 和 opencv 进行编码。

我有这个云室的黑白视频 (http://youtu.be/40wnB8ukI7s)。我想在移动的粒子轨道周围绘制轮廓。目前我正在使用 findContours 和 drawContours;但是,它会在所有白色像素周围绘制轮廓,包括那些快速出现和消失的像素。我不想在我的背景周围绘制轮廓,闪烁的白色像素。

我的问题是背景也在移动,所以背景减法不起作用。有没有办法:

a) 只绘制一个轮廓,如果它在几帧中大致存在于相同的位置

b) 如果多个帧(可能至少 4 或 5 帧)不存在白色像素,则移除该像素

感谢您提供的任何帮助。

编辑:比较两个帧(firstFrame 和 secondFrame)的代码

Vec3b frameColour;
Vec3b frameColour2;
for (int x = 0; x < firstFrame.cols; x++){
for (int y = 0; y < firstFrame.rows; y++){
frameColour = firstFrame.at<Vec3b>(Point(x, y));
frameColour2 = secondFrame.at<Vec3b>(Point(x, y));
if(frameColour == white && frameColour2 == white){
secondFrameAfter.at<Vec3b>(Point(x, y)) = white;
}else{
secondFrameAfter.at<Vec3b>(Point(x, y)) = black;
}

}

}

最佳答案

您可以实现您的想法:

For each frame do:
For each white pixel do:
If the pixels in the neigbourhood of the last N frames are *mostly* white
Set the current pixel to white
Else
Set the current pixel to black

邻域可以定义为像素周围的 3x3 掩码。
大部分 指的是适当的阈值,假设 N 帧中的 80% 应该支持(白色)像素位置。
The red pixel is the current pixel (x,y) and the green pixels are its neigbourhood.
红色像素是当前像素 (x,y),绿色像素是它的邻域。比较像素 (x,y) 的相邻像素可以如下实现:

const int MASK_SIZE = 3;    
int numberOfSupportingFrames = 0;
for(int k = 0; k < N; k++)
{
Mat currentPreviousFrame = previousFrames.at(k);
bool whitePixelAvailable = false;
for(int i = x-(MASK_SIZE/2); i < x+(MASK_SIZE/2) && !whitePixelAvailable; i++)
{
for(int j = y-(MASK_SIZE/2); j < y+(MASK_SIZE/2) && !whitePixelAvailable; j++)
{
if(currentPreviousFrame.at<Vec3b>(Point(i, j)) == white)
{
whitePixelAvailable = true;
numberOfSupportingFrames++;
}
}
}
}
if((float)numberOfSupportingFrames / (float)N > 0.8)
secondFrameAfter.at<Vec3b>(Point(x, y)) = white;
else
secondFrameAfter.at<Vec3b>(Point(x, y)) = black;

之前的帧存储在 std::vector previousFrames 中。
该算法检查像素 (x,y) 的时空邻域。外层循环遍历相邻帧(时间邻域),而内部两个循环遍历相邻八个像素(空间邻域)。如果当前空间邻域中有一个白色像素,则前一帧支持当前像素 (x,y)。最后检查是否有足够的帧支持当前像素(80% 的先前帧应至少包含 8 个邻域中的白色像素)。
此代码应嵌套在您的两个 for 循环中,并进行一些修改(变量名、边界处理)。

关于c++ - 仅绘制存在于多个帧上的轮廓以消除闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26223662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com