OpenCV 将剪影与网络摄像头流隔离
OpenCV Isolate silhouette from webcam stream
我试图将一个人的轮廓与未知的视频流隔离开来。( 用户网络摄像头 ),使用 C++/Cinder/OpenCV
。我已经确定了轮廓并绘制了轮廓,但我没有得到整个人的轮廓,只是元素(头发,眼睛等)。
我正在使用:背景减法器MOG2 删除背景。模糊以消除噪音。自适应阈值。查找并绘制具有一定复杂性的轮廓。
法典:
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.pnghttp://barnabysheeran.com/outgoing/stackoverflow/ss_2.png
我希望这是一个全身充满的轮廓。
你可以在阈值化后使用侵蚀/扩张,这通常会消除噪音并拉伸白色区域,但我建议使用 BGSlibrary,我过去将它与 openFrameworks 结合使用,它确实是用于减去背景的不同算法的伟大集合。
此外,分割前的一些图像处理可能会有所帮助,但这只是一个理论。
相关文章:
- 带内存和隔离功能的SQLite
- 使用不同的CRT将新的C++代码与旧的(二进制)组件隔离开来的最佳方法是什么
- 如何使用隔离>终止执行来停止所有线程
- 从矢量中删除元素后出现隔离错误
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- 使用OpenCV和覆盆子上的多个网络摄像头拍摄延时摄影,出现多个V4L错误
- 在 gtest 中初始化堆栈上的引用变量的隔离错误
- 使用源读取器从网络摄像头源获取 H264 样本
- 线程时访问静态映射时出现隔离错误
- 为什么我不能让 3 个网络摄像头与 pthreads 并行运行?
- 从 OpenCV 3 切换到 OpenCV 4 会导致网络摄像头以最大 5 fps 的速度录制,而不是通常的 30 f
- 如何使用realsense摄像头调试ROS错误消息
- 比特币隔离见证钱包地址计算
- 并行快速排序分区中的隔离错误
- C++多线程程序:变量定义为类成员的隔离错误
- TFLite 隔离错误,通过获取C++输入和输出
- 我只是在寻找模板,在我的书中找到了这段代码,这显示了隔离错误?
- 如何将 v8::FunctionCallbackInfo<v8::Value> 数组从一个隔离复制到另一个隔离?
- pthread_create中错误 4 的隔离错误
- OpenCV 将剪影与网络摄像头流隔离