第一个Opencv 程序 对 摄像头视频流 取反

//对 摄像头视频流 取反

#include "cvcam.h"
#include "cv.h"
#include "highgui.h"
#include <cstdio>

void example2_4(IplImage*image)
{
cvNamedWindow("Example4-in");
   cvNamedWindow("Example4-out");
    cvShowImage("Example4-in",image);

IplImage *out=cvCreateImage(cvGetSize(image),
         IPL_DEPTH_8U,//多少位
         3);//多少色
cvSmooth(image,out,CV_GAUSSIAN,3,3);
 cvShowImage("Example4-out",out);
  cvReleaseImage(&out);
   cvWaitKey(0);
  cvDestroyWindow("Example4-in");
   cvDestroyWindow("Example4-out");
}

  int g_slider_position = 0;
  CvCapture* g_capture = NULL;
  void onTrackbarSlide(int pos)
  {
   //pos=g_slider_position;
      cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos);
  
 
  }

  void callback ( IplImage *image )//在图像上画一条水平蓝线
{
    IplImage *image1 = image;
    int i, j;
    assert ( image );
    for ( i = 0; i < image1->height/2; i += 10 )
    {
        for ( j = ( image1->widthStep ) * i;
              j < ( image1->widthStep ) * ( i + 1 );
              j += image1->nChannels )
        {
            image1->imageData[j] = ( char ) 255;
            image1->imageData[j + 1] = 0;
            image1->imageData[j + 2] = 0;
        }
    }
}
void main( int argc, char** argv )
{
// IplImage*img=cvLoadImage("C://zhongqiu.bmp",1);//
 cvNamedWindow("Example1",CV_WINDOW_AUTOSIZE);
 //g_capture=cvCreateFileCapture("F://opencv//aviConsoleOpencv//avid.avi");
 //g_capture = cvCaptureFromCAM(0); // capture from video device #0
     g_capture = cvCreateCameraCapture(0);
 int frames=(int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
 if(frames!=0){
  cvCreateTrackbar("position",
   "Example1",
   &g_slider_position,
   frames,
   onTrackbarSlide);
  
   
  
 }
 IplImage*frame;
 int height,width,step,channels;
  uchar *data;
  //uchar *data2;
  int i,j,k;
  // get the image data
 

 while(1){
  frame=cvQueryFrame(g_capture);
  if(!frame) break;
  // cvSetTrackbarPos("position","Example1", g_slider_position++);
 
      assert ( frame );
   height    = frame->height;
  width     = frame->width;
  step      = frame->widthStep;
  channels  = frame->nChannels;
  data      = (uchar *)frame->imageData;
   /* for ( i = 0; i <frame->height; i += 10 )
    {
        for ( j = (frame->widthStep ) * i;
              j < ( frame->widthStep ) * ( i + 1 );
              j +=  frame->nChannels )
        {
             frame->imageData[j] = ( char ) 255;
             frame->imageData[j + 1] = 0;
             frame->imageData[j + 2] = 0;
        }
    }
*/
   for(i=0;i<height;i++) {
    for(j=0;j<width;j++) {
     for(k=0;k<channels;k++){
                data[i*step+j*channels+k]=123-data[i*step+j*channels+k];
     }
    }
   }

   //cvcamSetProperty ( 0, CVCAM_PROP_CALLBACK, callback );
     //example2_4(frame);
  cvShowImage("Example1",frame);
  char c=cvWaitKey(33);
  if(c==27) break;
 }

  //cvNamedWindow("Example1",0);
 //cvShowImage("Example1",img);
 
 cvReleaseCapture(&g_capture);
 cvDestroyWindow("Example1");
 

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

听海拉拉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值