Results 1 to 2 of 2

Thread: Update Live Image from Camera

  1. #1
    Join Date
    Jun 2014
    Posts
    16
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Update Live Image from Camera

    I get one live image from camera each time I call the function "vc3d_GetImage(0,iTotalImage,true,&iRemainImg, pB)". After that I will call the function "loadImage(unsigned char *pB)" to display the image. However the image is not updated all the while. Only the last image is showed at the end. For example I call the function "vc3d_GetImage(0,iTotalImage,true,&iRemainImg, pB)" 5 times. The display is not updated 5 times. The display is only updated once (the fifth image) at the end. What has I done wrong?

    Qt Code:
    1. void MainWindow::on_pBCapture_clicked()
    2. {
    3. ui->lImageCount->setText("0");
    4. int iTotalImage = ui->sBTotalImage->value();
    5.  
    6. int iImgWidth, iImgHeight;
    7. int count = 0;
    8. unsigned char *pBuffer=NULL;
    9. unsigned char *pBuffer2=NULL;
    10.  
    11. /* to get the width and height of image */
    12. int iStatus = vc3d_GetImageSizeVr(0, &iImgWidth, &iImgHeight);
    13.  
    14. if (iStatus>0)
    15. {
    16. int iRemainImg = iTotalImage;
    17. pBuffer = new unsigned char[iImgWidth*iImgHeight];
    18. pBuffer2 = new unsigned char[iImgWidth*iImgHeight];
    19. // Get one image (or more when in a loop)
    20. do
    21. {
    22. unsigned char *pB;
    23. if (iRemainImg%2)
    24. {
    25. pB=pBuffer;
    26. }
    27. else
    28. {
    29. pB=pBuffer2;
    30. }
    31. /* Get the one image when this function is called */
    32. iStatus = vc3d_GetImage(0,iTotalImage,true,&iRemainImg, pB);
    33. if (iStatus == 1)
    34. {
    35. count++;
    36. ui->lImageCount->setText(QString::number(count));
    37. loadImage(pB);
    38. }
    39. //delete [] pBuffer;
    40. }while (iRemainImg>0 && iStatus>0);
    41. }
    42. }
    43.  
    44. void MainWindow::loadImage(unsigned char *pB)
    45. {
    46. QGraphicsScene* scene = new QGraphicsScene(this);
    47. ui->graphicsView->setScene(scene);
    48. QImage image = QImage(pB, 1280, 1024, QImage::Format_Indexed8);
    49. scene->clear();
    50. QGraphicsPixmapItem* pi = scene->addPixmap(QPixmap::fromImage(image));
    51. ui->graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
    52. ui->graphicsView->update();
    53. ui->graphicsView->viewport()->update();
    54. ui->graphicsView->show();
    55. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Update Live Image from Camera

    Updating a display widget in a loop like that won't give it enough time to redraw. Create a slot to capture and update single image and then use a timer with reasonable timeout to capture the image.
    Btw. creating new graphics scene just to display new image is not necessary, you can add first image with scene->addPixmap and then reuse the QGraphicsPixmapItem object by updating displayed pixmap with QGraphicsPixmapItem::setPixmap() method.

Similar Threads

  1. Replies: 0
    Last Post: 12th June 2013, 06:44
  2. Replies: 1
    Last Post: 9th June 2013, 23:16
  3. Qt application with live Active X camera feed.
    By bitChanger in forum Qt Programming
    Replies: 8
    Last Post: 4th September 2012, 19:26
  4. Replies: 0
    Last Post: 12th March 2012, 12:54
  5. Live Update data in table
    By abghosh in forum Qt Programming
    Replies: 8
    Last Post: 25th February 2010, 18:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.