Swapnil
Swapnil

Reputation: 21

How to manipulate individual pixels in Mat image in OpenCV 3.0.0-1.1 Java API

Until now, the previous versions of OpenCV JAVA API offered get() and put() methods in order to fetch and manipulate the individual pixels in a Mat image. But in OpenCV 3.0.0-1.1 Java API those methods are deprecated. So how can individual pixels be manipulated in this version.

Here is a list of deprecated methods: http://bytedeco.org/javacpp-presets/opencv/apidocs/deprecated-list.html

When I'm using the put() method in HIPI v2.0 (which supports latest OpenCV API), I'm getting the following error:

Image showing the error

What can I do to change particular pixels (given the indices)?

Upvotes: 1

Views: 1020

Answers (1)

Samuel Audet
Samuel Audet

Reputation: 4994

The recommended approach is via an Indexer as introduced in this post:
http://bytedeco.org/news/2014/12/23/third-release/

So, for example, in the case of a typical BGR/RGB 8-bit image:

UByteIndexer idx = mat.createIndexer();
idx.put(x, y, z, 255);
assert idx.get(x, y, z) == 255;

Upvotes: 1

Related Questions