Results 1 to 7 of 7

Thread: system gets struced when add 1000+ QPixmap items to scene

  1. #1
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default system gets struced when add 1000+ QPixmap items to scene

    hi,
    i need to extract the frames from the video file and then need to show all the frames in a time line. i have extracted all the frames and make each of the frame as QPixmap, then i am adding them to a scene. the problem is i have to add more than 3000 pixmaps to the scene (some times 5000+ images i need to add), the system getting struck when i add pix maps to the scene.

    this i have tried in 2 way

    1) i took 1 viwe & 1 Scene -> add all the pix maps to scene (by scaling them so that they will fit into time line).
    2) for each pixmap i took 1 view & 1 scene -> add each pix maps to corresponding scenes -> add all the views to scrollBar area .

    in both the ways system gets struck...
    each time i run the app its is adding the images one by one to timeline slowly after some time the application is getting struck, i am restarting my system each time i run this application.

    below i added screen shot how this app look like .

    i am not sure why this is happening, is this because of we are adding more items to the scene or else do we need to take any special care while dealing with Pixmap.
    here is the main code where app gets slow .

    Qt Code:
    1. m_scene->setSceneRect(rect); //set scene rect depnd on no.of images
    2.  
    3. for loop for all the images
    4. {
    5. QPixmap tempImage = QPixmap::fromImage(qImage);
    6. m_imageItem = new QGraphicsPixmapItem(tempImage);
    7. m_imageItem->scale(0.1,0.1);
    8. m_imageItem->setPos(pos);
    9. m_scene->addItem(m_imageItem); // add the images to time line scene
    10. }
    To copy to clipboard, switch view to plain text mode 

    thanks in advance :-) .



    vctool.jpgs
    Last edited by prasad.ece2; 19th March 2014 at 14:39.
    Thanks & Regards,
    Durga .

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

    Default Re: system gets struced when add 1000+ QPixmap items to scene

    Assuming 640x480, 8bit RGB, you need 5000*640*480*3 = 4608000000 bytes = 4394 mb = 4gb of memory for the image pixel data. Not mentioning memory needed for other parts of the application. Do you understand why the OS can't handle this ?
    Instead of displaying every single frame for such big file, display only every 50/100 frames as thumbnail and use some kind of scale with slider to give access to other frames (for example, video with 110K+ frames opened with VirtualDub). Trying to load them all into memory is killing your application. Who would like to manually browse through 5000 pictures anyway ?

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: system gets struced when add 1000+ QPixmap items to scene

    You probably want to scale the image, not the pixmap item.

    You are currently scaling the by 0.1 in both dimensions, reducing the visible image to a hundreth of its orginal size. But you still keep the image in its full size.

    If you scale the image and then create the pixmap item, each item will only have the thumbnail image to hold.

    Something you could try additionally is to use a QListView in icon view mode and write a simple list model that returns thumbnail images as Qt:ecorationRole value.

    That way the list view can decide which images it needs to fill its area and you only need to load and scale those.

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    prasad.ece2 (20th March 2014)

  5. #4
    Join Date
    Jan 2013
    Location
    Bangalore
    Posts
    49
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: system gets struced when add 1000+ QPixmap items to scene

    hai stampede, i am also facing same issue. i got to know why this is happening after reading your post. could you please explain how to display 50/100 frames as a thumbnail. i didn't get this how to do and how it will work as for this also need same memory right ?

    please let me know if is there any example in Qt to handle this.

    thank you very much.

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

    Default Re: system gets struced when add 1000+ QPixmap items to scene

    could you please explain how to display 50/100 frames as a thumbnail. i didn't get this how to do and how it will work as for this also need same memory right ?
    What I meant was to display frame number 0, then skip next 99 frames, display frame number 100, skip next 99 ... and so on. This way you can use 10% of required memory and still give the user a way to navigate the video with visual preview. Frames between the "key" frames could be simply marked as numbers, or ticks on the slider.
    You can also do what anda_skoa suggested, scaling the images to, lets say, 50x50 will require only 35 mb of memory for 5000 images.

  7. The following user says thank you to stampede for this useful post:

    prasad.ece2 (20th March 2014)

  8. #6
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: system gets struced when add 1000+ QPixmap items to scene

    hai anda_skoa,
    i have done as you said, but when i check the memory by launching task manager, the memory keep on increasing in a normal way. i have used Image.scaled(QSize(50,50)); to resize the image then created pixmap item.

    below is the changed code.

    Qt Code:
    1. m_scene->setSceneRect(0,0,55*f_totalFrames,55);
    2.  
    3. foreach(allFrames)
    4. {
    5. tempImage.scaled(QSize(50,50));
    6. QGraphicsPixmapItem* imageItem = new QGraphicsPixmapItem(tempImage);
    7. imageItem->scale(0.1,0.1);
    8. m_scene->addItem(imageItem);
    9. imageItem->setPos((f_frameNum*50)+10,0);
    10. }
    To copy to clipboard, switch view to plain text mode 

    thanks .
    Thanks & Regards,
    Durga .

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

    Default Re: system gets struced when add 1000+ QPixmap items to scene

    Qt Code:
    1. tempImage.scaled(QSize(50,50));
    To copy to clipboard, switch view to plain text mode 
    scaled() is a const method, you need to assign the result to the pixmap:
    Qt Code:
    1. tempImage = tempImage.scaled(QSize(50,50));
    2.  
    3. or
    4.  
    5. QGraphicsPixmapItem* imageItem = new QGraphicsPixmapItem(tempImage.scaled(50,50));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to make some items non movable on scene
    By tarunrajsingh in forum Qt Programming
    Replies: 8
    Last Post: 17th April 2013, 21:44
  2. Saving QGraphics Scene items
    By chaltier in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2012, 06:35
  3. adding QPixmap to scene
    By rogerholmes in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2009, 05:45
  4. add items into scene
    By Noxxik in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2009, 16:32
  5. Can't move Items in the scene
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2008, 09:40

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.