user2758510
user2758510

Reputation: 159

correspond values between two images in opencv / c++

I am new in image processing and opencv. I have two images. I want to find correspond values in the image 2 with the image 1. and then show it. is there any function in opencv to find correspond values between images?

thanks in advance.

Upvotes: 1

Views: 299

Answers (3)

Michael Burdinov
Michael Burdinov

Reputation: 4428

Mat corrVals;
bitwise_and(image2, image1>0, corrVals);

image1>0 will create temporary binary image with values 0 and 255. Than the only thing you need is to perform AND operation between pixels of your images, and store result somewhere. This is done by bitwise_and.

This is similar to approach suggested by @Mailerdaimon but uses much cheaper operations.

Upvotes: 4

carlosdc
carlosdc

Reputation: 12132

It is hard to say without looking at your images. This is a well studied problem in computer vision and OpenCV contains several algorithms for this. The problem you're looking at can be very easy or very hard, depending on:

  • your images, are the normal images? just shapes? binary?
  • where on the images lie the corresponding pixels
  • how fast you need this to run
  • how much variation there is between images, is it exactly the same pixel value?
  • is there camera movement?
  • is there variation in illumination?

You can start by looking at stereo matching and optical flow inside OpenCV.

Upvotes: 1

Mailerdaimon
Mailerdaimon

Reputation: 6080

You can threshold you image1 such that all Values you want are 1 and all other are 0.

Than you multiply image1 with image2.

cv::multiply(image1, image2, result, scale, dtype)

This will return an image with all values greater than zero from image2 that are marked in image1.

Upvotes: 1

Related Questions