使用通配符高效替换从网站上copy的代码

<span style="color: rgb(51, 153, 51);">#include <stdio.h></span>
<span style="color: rgb(51, 153, 51);">#include <cv.h></span>
<span style="color: rgb(51, 153, 51);">#include <cxcore.h></span>
<span style="color: rgb(51, 153, 51);">#include <highgui.h></span>
<span style="color: rgb(51, 153, 51);">#include <cvaux.h>//必须引此头文件</span>
<span style="color: rgb(153, 51, 51);">int</span> main<span style="color: rgb(0, 153, 0);">(</span> <span style="color: rgb(153, 51, 51);">int</span> argc<span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(153, 51, 51);">char</span><span style="color: rgb(51, 153, 51);">**</span> argv <span style="color: rgb(0, 153, 0);">)</span>
<span style="color: rgb(0, 153, 0);">{</span> 

   IplImage<span style="color: rgb(51, 153, 51);">*</span> pFrame <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 0);"><strong>NULL</strong></span><span style="color: rgb(51, 153, 51);">;</span>   
   IplImage<span style="color: rgb(51, 153, 51);">*</span> pFrImg <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 0);"><strong>NULL</strong></span><span style="color: rgb(51, 153, 51);">;</span> 
   IplImage<span style="color: rgb(51, 153, 51);">*</span> pBkImg <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 0);"><strong>NULL</strong></span><span style="color: rgb(51, 153, 51);">;</span>   
   CvCapture<span style="color: rgb(51, 153, 51);">*</span> pCapture <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 0);"><strong>NULL</strong></span><span style="color: rgb(51, 153, 51);">;</span>   
   <span style="color: rgb(153, 51, 51);">int</span> nFrmNum <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 221);">0</span><span style="color: rgb(51, 153, 51);">;</span>

   cvNamedWindow<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"video"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span> 
   cvNamedWindow<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"background"</span><span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span> 
   cvNamedWindow<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"foreground"</span><span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>   
   cvMoveWindow<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"video"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 221);">30</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 221);">0</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span> 
   cvMoveWindow<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"background"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 221);">360</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 221);">0</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span> 
   cvMoveWindow<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"foreground"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 221);">690</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 221);">0</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
   <span style="color: rgb(177, 177, 0);">if</span><span style="color: rgb(0, 153, 0);">(</span> argc <span style="color: rgb(51, 153, 51);">></span> <span style="color: rgb(0, 0, 221);">2</span> <span style="color: rgb(0, 153, 0);">)</span>   
   <span style="color: rgb(0, 153, 0);">{</span>     
      fprintf<span style="color: rgb(0, 153, 0);">(</span>stderr<span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(255, 0, 0);">"Usage: bkgrd [video_file_name]<span style="color: rgb(0, 0, 153);"><strong>\n</strong></span>"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>     
      <span style="color: rgb(177, 177, 0);">return</span> <span style="color: rgb(51, 153, 51);">-</span><span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(51, 153, 51);">;</span>   
   <span style="color: rgb(0, 153, 0);">}</span>


   <span style="color: rgb(102, 102, 102);"><em>//打开视频文件 </em></span>
   <span style="color: rgb(177, 177, 0);">if</span><span style="color: rgb(0, 153, 0);">(</span>argc <span style="color: rgb(51, 153, 51);">==</span> <span style="color: rgb(0, 0, 221);">2</span><span style="color: rgb(0, 153, 0);">)</span>   
      <span style="color: rgb(177, 177, 0);">if</span><span style="color: rgb(0, 153, 0);">(</span> <span style="color: rgb(51, 153, 51);">!</span><span style="color: rgb(0, 153, 0);">(</span>pCapture <span style="color: rgb(51, 153, 51);">=</span> cvCaptureFromFile<span style="color: rgb(0, 153, 0);">(</span>argv<span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">)</span>     
      <span style="color: rgb(0, 153, 0);">{</span>   
         fprintf<span style="color: rgb(0, 153, 0);">(</span>stderr<span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(255, 0, 0);">"Can not open video file %s<span style="color: rgb(0, 0, 153);"><strong>\n</strong></span>"</span><span style="color: rgb(51, 153, 51);">,</span> argv<span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>   
         <span style="color: rgb(177, 177, 0);">return</span> <span style="color: rgb(51, 153, 51);">-</span><span style="color: rgb(0, 0, 221);">2</span><span style="color: rgb(51, 153, 51);">;</span>     
      <span style="color: rgb(0, 153, 0);">}</span>
   <span style="color: rgb(102, 102, 102);"><em>//打开摄像头 </em></span>
   <span style="color: rgb(177, 177, 0);">if</span> <span style="color: rgb(0, 153, 0);">(</span>argc <span style="color: rgb(51, 153, 51);">==</span> <span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(0, 153, 0);">)</span>   
      <span style="color: rgb(177, 177, 0);">if</span><span style="color: rgb(0, 153, 0);">(</span> <span style="color: rgb(51, 153, 51);">!</span><span style="color: rgb(0, 153, 0);">(</span>pCapture <span style="color: rgb(51, 153, 51);">=</span> cvCaptureFromCAM<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 153, 51);">-</span><span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">)</span>     
      <span style="color: rgb(0, 153, 0);">{</span>   
         fprintf<span style="color: rgb(0, 153, 0);">(</span>stderr<span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(255, 0, 0);">"Can not open camera.<span style="color: rgb(0, 0, 153);"><strong>\n</strong></span>"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>   
         <span style="color: rgb(177, 177, 0);">return</span> <span style="color: rgb(51, 153, 51);">-</span><span style="color: rgb(0, 0, 221);">2</span><span style="color: rgb(51, 153, 51);">;</span>     
      <span style="color: rgb(0, 153, 0);">}</span>   

                <span style="color: rgb(102, 102, 102);"><em>//初始化高斯混合模型参数</em></span>
   CvGaussBGModel<span style="color: rgb(51, 153, 51);">*</span> bg_model<span style="color: rgb(51, 153, 51);">=</span><span style="color: rgb(0, 0, 0);"><strong>NULL</strong></span><span style="color: rgb(51, 153, 51);">;</span>

   <span style="color: rgb(177, 177, 0);">while</span><span style="color: rgb(0, 153, 0);">(</span>pFrame <span style="color: rgb(51, 153, 51);">=</span> cvQueryFrame<span style="color: rgb(0, 153, 0);">(</span> pCapture <span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">)</span>   
   <span style="color: rgb(0, 153, 0);">{</span>     
      nFrmNum<span style="color: rgb(51, 153, 51);">++;</span>           
      <span style="color: rgb(177, 177, 0);">if</span><span style="color: rgb(0, 153, 0);">(</span>nFrmNum <span style="color: rgb(51, 153, 51);">==</span> <span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(0, 153, 0);">)</span>   
      <span style="color: rgb(0, 153, 0);">{</span>    
         pBkImg <span style="color: rgb(51, 153, 51);">=</span> cvCreateImage<span style="color: rgb(0, 153, 0);">(</span>cvSize<span style="color: rgb(0, 153, 0);">(</span>pFrame<span style="color: rgb(51, 153, 51);">-></span>width<span style="color: rgb(51, 153, 51);">,</span> pFrame<span style="color: rgb(51, 153, 51);">-></span>height<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">,</span>  IPL_DEPTH_8U<span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(0, 0, 221);">3</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>   
         pFrImg <span style="color: rgb(51, 153, 51);">=</span> cvCreateImage<span style="color: rgb(0, 153, 0);">(</span>cvSize<span style="color: rgb(0, 153, 0);">(</span>pFrame<span style="color: rgb(51, 153, 51);">-></span>width<span style="color: rgb(51, 153, 51);">,</span> pFrame<span style="color: rgb(51, 153, 51);">-></span>height<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">,</span>  IPL_DEPTH_8U<span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>     


         <span style="color: rgb(102, 102, 102);"><em>//高斯背景建模,pFrame可以是多通道图像也可以是单通道图像</em></span>
          <span style="color: rgb(102, 102, 102);"><em>//cvCreateGaussianBGModel函数返回值为CvBGStatModel*,</em></span>
          <span style="color: rgb(102, 102, 102);"><em>//需要强制转换成CvGaussBGModel*</em></span>
         bg_model <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 153, 0);">(</span>CvGaussBGModel<span style="color: rgb(51, 153, 51);">*</span><span style="color: rgb(0, 153, 0);">)</span>cvCreateGaussianBGModel<span style="color: rgb(0, 153, 0);">(</span>pFrame<span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 0, 221);">0</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
      <span style="color: rgb(0, 153, 0);">}</span>     
      <span style="color: rgb(177, 177, 0);">else</span>
      <span style="color: rgb(0, 153, 0);">{</span>    
                 <span style="color: rgb(102, 102, 102);"><em>//更新高斯模型</em></span>
        cvUpdateBGStatModel<span style="color: rgb(0, 153, 0);">(</span>pFrame<span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 153, 0);">(</span>CvBGStatModel <span style="color: rgb(51, 153, 51);">*</span><span style="color: rgb(0, 153, 0);">)</span>bg_model <span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>

         <span style="color: rgb(102, 102, 102);"><em>//pFrImg为前景图像,只能为单通道</em></span>
          <span style="color: rgb(102, 102, 102);"><em>//pBkImg为背景图像,可以为单通道或与pFrame通道数相同</em></span>
         cvCopy<span style="color: rgb(0, 153, 0);">(</span>bg_model<span style="color: rgb(51, 153, 51);">-></span>foreground<span style="color: rgb(51, 153, 51);">,</span>pFrImg<span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(0, 0, 221);">0</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
            cvCopy<span style="color: rgb(0, 153, 0);">(</span>bg_model<span style="color: rgb(51, 153, 51);">-></span>background<span style="color: rgb(51, 153, 51);">,</span>pBkImg<span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(0, 0, 221);">0</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>

         <span style="color: rgb(102, 102, 102);"><em>//把图像正过来</em></span>
         pBkImg<span style="color: rgb(51, 153, 51);">-></span>origin<span style="color: rgb(51, 153, 51);">=</span><span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(51, 153, 51);">;</span>
         pFrImg<span style="color: rgb(51, 153, 51);">-></span>origin<span style="color: rgb(51, 153, 51);">=</span><span style="color: rgb(0, 0, 221);">1</span><span style="color: rgb(51, 153, 51);">;</span>

         cvShowImage<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"video"</span><span style="color: rgb(51, 153, 51);">,</span> pFrame<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>    
         cvShowImage<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"background"</span><span style="color: rgb(51, 153, 51);">,</span> pBkImg<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>    
         cvShowImage<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"foreground"</span><span style="color: rgb(51, 153, 51);">,</span> pFrImg<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>       
         <span style="color: rgb(177, 177, 0);">if</span><span style="color: rgb(0, 153, 0);">(</span> cvWaitKey<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 221);">2</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(51, 153, 51);">>=</span> <span style="color: rgb(0, 0, 221);">0</span> <span style="color: rgb(0, 153, 0);">)</span>      
            <span style="color: rgb(0, 0, 0);"><strong>break</strong></span><span style="color: rgb(51, 153, 51);">;</span>     
      <span style="color: rgb(0, 153, 0);">}</span>     

   <span style="color: rgb(0, 153, 0);">}</span>

   <span style="color: rgb(102, 102, 102);"><em>//释放高斯模型参数占用内存   </em></span>
   cvReleaseBGStatModel<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">(</span>CvBGStatModel<span style="color: rgb(51, 153, 51);">**</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">&</span>bg_model<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
   cvDestroyWindow<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"video"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span> 
   cvDestroyWindow<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"background"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span> 
   cvDestroyWindow<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(255, 0, 0);">"foreground"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>   
   cvReleaseImage<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 153, 51);">&</span>pFrImg<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span> 
   cvReleaseImage<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 153, 51);">&</span>pBkImg<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>   
   cvReleaseCapture<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 153, 51);">&</span>pCapture<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>   
   <span style="color: rgb(177, 177, 0);">return</span> <span style="color: rgb(0, 0, 221);">0</span><span style="color: rgb(51, 153, 51);">;</span>
<span style="color: rgb(0, 153, 0);">}</span>

    我们可以看到在这个网站上的代码因为上传时不小心而导致我们copy之后出现了大量的<格式>的内容,想要运行这段代码就不得不把这些类似的代码给去掉?那么这种问题如何解决呢?
     我们可以通过word中的替换来高效解决这个问题;我们首先把代码复制到一个新word中,然后通过点击Ctrl+H,唤醒替换窗口,在查找内容中我们输入[<]*[>],然后在搜索选项中选择使用通配符,之后就可以高效的替换所有的<格式>了;另外关于其他的通配符选项可以参考通配符链接
     在这个网页上,我们可以看到很多有效的通配符,这样结合word就可以帮助我们避免这种机械的劳动了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值