Opencv的cvDilate函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Opencv的cvDilate函数相关的知识,希望对你有一定的参考价值。

新手在做视屏开发的时候发现这样一个问题。环境,MFC, 录制720*576视屏。
int CStreamWndMedia::ProcessUltraData(int *area)

int count;
double area_d = 0.0;
CvSeq *contour = NULL;
CvMemStorage *stor = cvCreateMemStorage(0);
CvSeq *cont = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint), stor);

m_pImpImage->imageData = m_UltrapDataBack;
cvThreshold(m_pImpImage, m_pImpImage, THRESHOLD_LOW, THRESHOLD_HIGH, CV_THRESH_BINARY);
cvDilate(m_pImpImage, m_pImpImage);
CopyROIData(m_UltrapDataBack); //get the ROI rect

*area = (int)area_d;
cvReleaseMemStorage(&stor);
return count;
在这里我测试了一下时间发现cvThreshold(m_pImpImage, m_pImpImage, THRESHOLD_LOW, THRESHOLD_HIGH, CV_THRESH_BINARY);这个函数处理一帧需要8毫秒到10毫秒的时间
cvDilate(m_pImpImage, m_pImpImage);这个函数竟然要37毫秒左右。请问这是怎么回事?如果使用这个函数的话就不能达到录制25帧的视频,很纠结,求高手分析原因。另求,请问上面的二值化函数自己写是否会提升效率。

Well, adding a processing step would always increase the processing duration.
It would be hard to explain why it takes 37ms to process, but its pretty straightforward that it must have something to do with the algorithm or even the way that memory is aligned. Since you would need it anyway, just keep it.
I am assuming you are also looking for a way to improve the performence, for sake of simplicity, just try the release mode
It could help to improve a lot. Good luck.追问

Thank you a lot. It is really release mode.What I want is to reduce the time to improving efficiency.

追答

How?
By creating a new function that do the same work as cvDilate()?

追问

yes,I want to .But now I find another problem.If I do not use cvDilate(),This function CDC* pDC = GetDc(); It will take almost 35ms.I do not why.This function should not take so much time. My Email:zhang19890513@gmail.com.Email me.Thanks a lot.

追答

hmmm
I hate to say this, but what you are asking doesn't make much sense to me.
1) Are you trying to develop a function that do the same job and take less time than those provided in OpenCV or WinAPI?
2) I have a hard time with reading your code, especially when part of it is missing.
3) If you consider CvDilate as necessary then keep it. If you feel like it slows you down, get rid of it and find another way through.
4) If you are truely looking for an answer, list your problem step by step.

Thank you

追问

Also Thanks a lot.Due to my poor English,it is hard to explan it clearly.I will try my best to find out the way to solve the problem.Thank you.

参考技术A 我想到贫困地区体验一下生活追问

去吧,没人拦着你,最好去菲律宾

opencv中cvScalarAll函数啥意思???

如题,谢谢

  opencv中cvScalarAll函数:
  CvScalar就是一个包含四个元素的结构体变量。
  CvScalar定义可存放1—4个数值的数值,其结构如下。
  typedef struct CvScalar
  
   double val[4];
  
  CvScalar;
  ------------------------------------------------
  CvScalar pt;
  如果使用的图像是1通道的,则pt.val[0]中存储数据
  如果使用的图像是3通道的,则pt.val[0],pt.val[1],pt.val[2]中存储数据
  ==============================
  cvGet2D 获得某个点的值, idx0=height 行值, idx1=width 列值。
  CVAPI(CvScalar) cvGet2D( const CvArr* arr, int idx0, int idx1 );
  -----------------------------------------------
  cvSet2D 给某个点赋值。
  CVAPI(void) cvSet2D( CvArr* arr, int idx0, int idx1, CvScalar value );
  -----------------------------------------------
  所以,cvGet2D的返回类型和cvSet2D中value的类型都是CvScalar,这样定义一个CvScalar变量再调用函数就OK了。
参考技术A inline CvScalar cvScalarAll( double val0123 );
同时设定VAL0,1,2,3的值;

 OpenCV里的Scalar:all的意思:
  scalar所有元素设置为0,其实可以scalar::all(n),就是原来的CvScalarAll(n);
  OpenCV的全称是:Open Source Computer Vision Library。OpenCV是一个基于(开源)发行的跨平台计算机视觉库,可以运行在Linux、Windows和Mac OS操作系统上。
  它轻量级而且高效——由一系列 C 函数和少量 C++ 类构成,同时提供了Python、Ruby、MATLAB等语言的接口,实现了图像处理和计算机视觉方面的很多通用算法。
参考技术B inline CvScalar cvScalarAll( double val0123 );
同时设定VAL0,1,2,3的值

以上是关于Opencv的cvDilate函数的主要内容,如果未能解决你的问题,请参考以下文章

在Emgu中使用Erode和Dilate(OpenCV for C#)

详解图像形态学操作之图形的腐蚀和膨胀的概念和运算过程,并利用OpenCV的函数erode()和函数dilate()对图像进行腐蚀和膨胀操作

OpenCV常用基本处理函数图像梯度

膨胀函数cvDilate

这些opencv函数是由ARM NEON加速的吗? [关闭]

OpenCV-Python教程:形态学变换~腐蚀和膨胀(erode,dilate)