Reader small image

You're reading from  Computer Vision with OpenCV 3 and Qt5

Product typeBook
Published inJan 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788472395
Edition1st Edition
Languages
Right arrow
Author (1)
Amin Ahmadi Tazehkandi
Amin Ahmadi Tazehkandi
author image
Amin Ahmadi Tazehkandi

Amin Ahmadi Tazehkandi is an Iranian author, developer, and a computer vision expert.Amin Ahmadi Tazehkandi is an Iranian author, developer, and a computer vision expert. He completed his computer software engineering studies in Iran and has worked for numerous software and industrial companies around the world.
Read more about Amin Ahmadi Tazehkandi

Right arrow

Chapter 5. The Graphics View Framework

Now that we are familiar with the basic building blocks of computer vision applications in both Qt and OpenCV frameworks, we can move on to learn more about the development of the visualization part in computer vision applications. Talk about computer vision and every user immediately looks for some preview image or video. Take any image editor that you want, for example, they all contain an area on their user interface that is immediately noticeable and can be easily recognized from the rest of the components on the GUI, by some border or even simple lines. The same can be said about the video editing software and literally anything that needs to work with visual concepts and media input sources. Also, the exact same reasoning is true for computer vision applications that we will create. Of course, there are cases where the result of the process is simply displayed as numerical values or sent over the network to some other party involved with the process...

The Scene-View-Item architecture


As it was mentioned in the introduction, the View Framework in Qt (or simply Qt from now on) divides possible graphics-related objects that you need to deal with into three major categories, which are Scene, View, and Items. Qt includes classes with quite noticeable names to handle each part of this architecture. Even though in theory it's easy to separate them from each other, in practice, they are very much intertwined. This means we cannot really dig deep into one of them without mentioning the others. Clear out one part of the architecture and you'll have no graphics at all. Also, taking another look at the architecture, we can see the model-view design pattern where the model (in this case, the scene) is totally unaware of how, or which part of it is displayed. As it's called in Qt, this is an Item-based approach to Model-View programming and we'll keep that in mind while also get, a brief idea of what each one of them is in practice:

  • The Scene or QGraphicsScene...

The Scene, QGraphicsScene


This class provides almost all methods required for multiple graphics items (QGraphicsItem), even though we only used it with a single QGraphicxPixmapItemin the previous example. In this section, we will review some of the most important functions in this class. As it was mentioned before, we'll mainly focus on the properties and methods required for our use case, since covering all methods, although they are all important, would be fruitless for the purpose of our book. We will skip the constructor functions of QGraphicsScene since they are simply used to take the dimensions of the scene and create a scene accordingly. As for the rest of the methods and properties, here they are, and for some of them that may not be too obvious, you can find a simple example code that you can try out with the Graphics_Viewer project we created earlier in this chapter:

  • The addEllipse, addLine, addRect, and addPolygon functions, as it can be guessed from their names, can be used...

The Items, QGraphicsItem


This is the base class of all items drawn on the scene. It contains methods and properties to deal with drawing each item, collision detection (with other items), handling mouse clicks and other events, and much more. Even though you can subclass it and create your own graphical items, Qt provides a set of subclasses too, which can be used for most (if not all) of the daily graphical tasks. Here are those subclasses, some of which we already used in the previous examples, directly or indirectly:

  • QGraphicsEllipseItem
  • QGraphicsLineItem
  • QGraphicsPathItem
  • QGraphicsPixmapItem
  • QGraphicsPolygonItem
  • QGraphicsRectItem
  • QGraphicsSimpleTextItem
  • QGraphicsTextItem

As it was previously mentioned, QGraphicsItem provides numerous functions and properties to deal with the problems and tasks in a graphical application. In this section, we'll go through some of the most important members in QGraphicsItem that consequently help us by getting familiar with its subclasses previously mentioned...

The View, QGraphicsView


We're down to the last part of The Graphics View Framework in Qt. The QGraphicsView class is a Qt Widget class that can be placed on a window to display QGraphicsScene, which itself contains a number of QGraphicsItem subclasses and/or widgets. Similar to the QGraphicsScene class, this class also provides tons of capabilities, methods, and properties to deal with the visualization part of the graphics. We'll review some of the most important ones in the following list, and then we'll learn how to subclass QGraphicsView and extend it to have several important capabilities in our comprehensive vision application, such as zoom in, zoom out, item selection, and so on. So, here are the methods and members of the QGraphicsView class that we'll need in a computer vision project:

  • The alignment and setAlignment functions can be used to set the alignment of the scene in the view. It's important to note that this will only have a visible effect when the view can completely display...

Summary


We've come a long way since the starting chapters of the book, and by now, we are fully equipped with lots of useful techniques to take on the task of computer vision application development. In all of the previous chapters, including the one we just finished, you learned more about the required skills to create a powerful and comprehensive application (in general, for the most part) rather than just focusing on the computer vision (OpenCV skills to be precise) aspect of it. You learned how to create applications that support multiple languages, themes and styles, plugins; and in this chapter, you learned how to visualize images and graphical items in a scene and on a view. We are now armed with almost everything we need to dig deeper into the world of computer vision application development.

In Chapter 6, Image Processing in OpenCV, you will learn more about OpenCV and possible image processing techniques in it. For each learned subject, we'll simply assume that we're creating a...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Computer Vision with OpenCV 3 and Qt5
Published in: Jan 2018Publisher: PacktISBN-13: 9781788472395
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Amin Ahmadi Tazehkandi

Amin Ahmadi Tazehkandi is an Iranian author, developer, and a computer vision expert.Amin Ahmadi Tazehkandi is an Iranian author, developer, and a computer vision expert. He completed his computer software engineering studies in Iran and has worked for numerous software and industrial companies around the world.
Read more about Amin Ahmadi Tazehkandi