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
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenCV Computer Vision with Java

You're reading from   OpenCV Computer Vision with Java Create multiplatform computer vision desktop and web applications using the combination of OpenCV and Java

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781783283972
Length 174 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Daniel Lelis Baggio Daniel Lelis Baggio
Author Profile Icon Daniel Lelis Baggio
Daniel Lelis Baggio
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Setting Up OpenCV for Java FREE CHAPTER 2. Handling Matrices, Files, Cameras, and GUIs 3. Image Filters and Morphological Operators 4. Image Transforms 5. Object Detection Using Ada Boost and Haar Cascades 6. Detecting Foreground and Background Regions and Depth with a Kinect Device 7. OpenCV on the Server Side Index

Pixel manipulation


Pixel manipulation is often required for one to access pixels in an image. There are several ways to do this and each one has its advantages and disadvantages. A straightforward method to do this is the put(row, col, value) method. For instance, in order to fill our preceding matrix with values {1, 2, 3}, we will use the following code:

for(int i=0;i<image.rows();i++){
  for(int j=0;j<image.cols();j++){ 
    image.put(i, j, new byte[]{1,2,3});
  }
}

Tip

Note that in the array of bytes {1, 2, 3}, for our matrix, 1 stands for the blue channel, 2 for the green, and 3 for the red channel, as OpenCV stores its matrix internally in the BGR (blue, green, and red) format.

It is okay to access pixels this way for small matrices. The only problem is the overhead of JNI calls for big images. Remember that even a small 640 x 480 pixel image has 307,200 pixels and if we think about a colored image, it has 921,600 values in a matrix. Imagine that it might take around 50ms to make...

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