Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenCV Essentials

You're reading from   OpenCV Essentials Acquire, process, and analyze visual content to build full-fledged imaging applications using OpenCV

Arrow left icon
Product type Paperback
Published in Aug 2014
Publisher
ISBN-13 9781783984244
Length 214 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Getting Started FREE CHAPTER 2. Something We Look At – Graphical User Interfaces 3. First Things First – Image Processing 4. What's in the Image? Segmentation 5. Focusing on the Interesting 2D Features 6. Where's Wally? Object Detection 7. What Is He Doing? Motion 8. Advanced Topics Index

Our first GPU-based program


In this section, we show two versions of the same program: one version uses the CPU to perform computations, and the other version uses the GPU. These two examples are called edgesCPU and edgesGPU, respectively, and allow us to point out the differences when using the GPU module in OpenCV.

The edgesCPU example is presented in the first place:

#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp" 
using namespace cv;

int main(int argc, char** argv){
if ( argc < 2 ){
        std::cout << "Usage: ./edgesGPU <image>" << std::endl;
        return -1;
    }
    Mat orig = imread(argv[1]);
    Mat gray, dst;

    bilateralFilter(orig,dst,-1,50,7);
    cvtColor(dst,gray,COLOR_BGR2GRAY);
    Canny(gray,gray,7,20);

    imshow("Canny Filter", gray);
    waitKey(0);

    return 0;
}

Now the edgesGPU example is shown as follows:

#include <iostream>
#include <opencv2...
lock icon The rest of the chapter is locked
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.
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 $19.99/month. Cancel anytime
Banner background image