• 6132阅读
  • 3回复

求助显示视频数据时屏幕闪烁的问题 [复制链接]

上一主题 下一主题
离线dongmingyi
 
只看楼主 倒序阅读 楼主  发表于: 2006-09-11
在网上找到了一段视频显示的代码,如下:


class PictureDisplay : public QWidget     // picture display widget
{
public:
  PictureDisplay(QWidget* parent, const char* name=0, int f=0);
  ~PictureDisplay();
protected:
  void   paintEvent( QPaintEvent * );
public :
  QPixmap pixmap;
private:
};




PictureDisplay::PictureDisplay(QWidget* parent, const char* name, int f):QWidget(parent, name, f)
{
  ;
}

PictureDisplay::~PictureDisplay()
{
;
}

void PictureDisplay::paintEvent( QPaintEvent * )
{
  QPainter paint( this );         // paint widget
  m.lock();
  paint.drawPixmap( 0, 0, pixmap );
  m.unlock();
}

void foo(IplImage *ipl_img ,QImage *q)
{
  int x;
  int y;
  char *data = ipl_img->imageData;
  for( y = 0; y < ipl_img->height; y++, data += ipl_img->widthStep )
  for( x = 0; x < ipl_img->width; x++ )
    {
        uint *p = (uint*)q->scanLine(y) + x;
        *p = qRgb(data[x * ipl_img->nChannels+2],data[x * ipl_img->nChannels +1],data[x * ipl_img->nChannels]);
    }
}


class Capturer : public QThread
{
  public:
  Capturer(int camnr);
  ~Capturer();
  virtual void run();
  PictureDisplay *p;
  IplImage *i;
  CCamera   c;
  QImage   *q;
};

Capturer :: Capturer(int camnr)
{
  c.connect(camnr);
  CvSize sz = cvSize(320,240);
  c.setSize(sz);
  i = cvCreateImage(sz,8,3);
  q = new QImage();
  q->create(320,240,32);
}

Capturer :: ~Capturer()
{
  c.disconnect();
  delete(q);
}

void Capturer ::run()
{
  while(true)
  {
    c.capture(i);
    foo(i,q);
    m.lock();
    p->pixmap.convertFromImage(*q);
    m.unlock();
    p->repaint();
  }
}



int main( int argc, char **argv )
{
  QApplication a( argc, argv );     // QApplication required!
  cvvInitSystem(0,0);
  QSplitter *s1 = new QSplitter( QSplitter::Vertical, 0 , "main" );

  PictureDisplay *test = new PictureDisplay(s1);     // create picture display

  a.setMainWidget(s1);         // set main widget
  s1->show();           // show it
 
  Capturer t1(0);
  t1.p = test;
  t1.start();

  return a.exec();           // start event loop

}

我写的程序大概思想和它的一样,现在出现了一个问题 视频图像的闪烁 ,不知如果解决。
[ 此贴被XChinux在2006-09-11 20:50重新编辑 ]
离线dongmingyi
只看该作者 1楼 发表于: 2006-09-11
谢谢各位,问题基本上解决了
离线shiroki

只看该作者 2楼 发表于: 2006-09-13
怎么解决的亚,是加了doublebuffer吗
--
shiro is White
ki is tree
http://www.cuteqt.com
论坛 http://www.cuteqt.com/bbs
博客 http://www.cuteqt.com/blog
博客镜像: http://sites.cuteqt.com/cuteqt
Linux/Qt/嵌入式讨论群 http://qun.qq.com/air/5699823
离线keerbin
只看该作者 3楼 发表于: 2009-04-02
dongmingyi ,素质太差,只会求助,问题自己解决了,都不共享一下解决办法,
这种人,太自私
快速回复
限100 字节
 
上一个 下一个