PDA

View Full Version : system gets struced when add 1000+ QPixmap items to scene



prasad.ece2
19th March 2014, 15:29
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 .




m_scene->setSceneRect(rect); //set scene rect depnd on no.of images

for loop for all the images
{
QPixmap tempImage = QPixmap::fromImage(qImage);
m_imageItem = new QGraphicsPixmapItem(tempImage);
m_imageItem->scale(0.1,0.1);
m_imageItem->setPos(pos);
m_scene->addItem(m_imageItem); // add the images to time line scene
}



thanks in advance :-) .



10147s

stampede
19th March 2014, 16:14
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 (http://img.tamindir.com/ti_e_ul/Dramacydal/virtual-dub-ss-tamindir.jpg)). Trying to load them all into memory is killing your application. Who would like to manually browse through 5000 pictures anyway ?

anda_skoa
19th March 2014, 16:57
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::DecorationRole 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,
_

DURGAPRASAD NEELAM
19th March 2014, 20:05
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.

stampede
19th March 2014, 22:00
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.

prasad.ece2
20th March 2014, 06:34
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.




m_scene->setSceneRect(0,0,55*f_totalFrames,55);

foreach(allFrames)
{
tempImage.scaled(QSize(50,50));
QGraphicsPixmapItem* imageItem = new QGraphicsPixmapItem(tempImage);
imageItem->scale(0.1,0.1);
m_scene->addItem(imageItem);
imageItem->setPos((f_frameNum*50)+10,0);
}



thanks .

stampede
20th March 2014, 08:48
tempImage.scaled(QSize(50,50));
scaled() is a const method, you need to assign the result to the pixmap:

tempImage = tempImage.scaled(QSize(50,50));

or

QGraphicsPixmapItem* imageItem = new QGraphicsPixmapItem(tempImage.scaled(50,50));