gpt4 book ai didi

c++ - OpenCV 从网络摄像头流中分离剪影

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:03 24 4
gpt4 key购买 nike

我正在尝试从未知视频流中分离出一个人的轮廓。 (用户网络摄像头),使用 C++/Cinder/OpenCV。我已经知道识别和绘制轮廓,但我没有得到整个人的轮廓,只是元素(头发、眼睛等)

我正在使用:BackgroundSubtractorMOG2 去除背景。模糊以消除噪音。自适应阈值。查找并绘制一定复杂度的轮廓。

代码:

Surface surface;
surface = mCapture.getSurface();

// To texture for display
textureCapture = Texture( surface );

// Greyscale
Mat matGrey( toOcv( surface ) );

// Output
Mat matForeground, matBackground;

// Build foreground & background
mog( matGrey, matForeground, -1 );
mog.getBackgroundImage( matBackground );

// Build countours
Mat matContourTemp = matForeground.clone();

// Blur to remove noise
Mat matBlurred = matContourTemp.clone();
cv::GaussianBlur( matContourTemp, matBlurred, cv::Size( 9, 9 ), 0 );

textureBlurred = Texture( fromOcv( matBlurred ) );

// Adaptive threshold
Mat matThresh = matContourTemp.clone();
adaptiveThreshold( matBlurred, matThresh, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, 3, 0 );

textureThreshold = Texture( fromOcv( matThresh ) );

// Contours
vector<cv::Vec4i> hierarchy;

// Find
contours.clear();
findContours( matThresh, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point( 0, 0 ) );

// Draw contours
Mat matContourImage( matForeground.size(), CV_8UC3, cv::Scalar( 0, 0, 0 ) );

Scalar colors[ 3 ];
colors[ 0 ] = Scalar( 255, 255, 255 );

for( size_t idx = 0; idx < contours.size(); idx++){

if( contours[ idx ].size() > 40 ){

cv::drawContours(
matContourImage, contours, idx,
colors[ 0 ], -3,
100,
hierarchy,
0,
cv::Point( 0, 0 ) );
};
};
textureContour = Texture( fromOcv( matContourImage ) );

输出:(我太初级了,无法发布图片)

http://barnabysheeran.com/outgoing/stackoverflow/ss_1.png http://barnabysheeran.com/outgoing/stackoverflow/ss_2.png

我希望这是一个充满全身的剪影。

最佳答案

你可以使用 erode/dilate在阈值化之后,通常会去除噪声并拉伸(stretch)白色区域,但我建议使用 BGSlibrary我过去将它与 openFrameworks 结合使用,它确实是用于减去背景的不同算法的绝佳集合。

在分割之前进行一些图像处理可能会有所帮助,但这只是一种理论。

关于c++ - OpenCV 从网络摄像头流中分离剪影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13749053/

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