Cybersupernova
Cybersupernova

Reputation: 1839

OpenCV: using GraphCutSeamFinder to stitch two images with best seam

I have been making an automatic panorama stitcher in python and now stuck in seam finding step. Following is my code in the structure which I understood from opencv docs.

im1 = cv2.imread('n3/0.jpg')
im2 = cv2.imread('n3/5.jpg')

c1 = [0,0]
c2 = [5,130] #calculated using ORB feature matching

mask1 = np.full(im1.shape[:2], 255)
mask2 = np.full(im2.shape[:2], 255)

finder = cv2.detail_GraphCutSeamFinder("COST_COLOR_GRAD")
finder.find([im1, im2], [c1, c2], [mask1, mask2])

This gives the following error which is not understandable by me.

cv2.error: OpenCV(4.1.2) /io/opencv/modules/imgproc/include/opencv2/imgproc/detail/gcgraph.hpp:121: error: (-215:Assertion failed) w>=0 && revw>=0 in function 'addEdges'

This is the simplest example which I can set up, please help on what I am doing wrong.

AS requested, I am adding input images

n3/0.jpg n3/0.jpg

n3/5.jpg n3/5.jpg

UPADTE

By using another method I have achieved the desired result, but I still want to use the inbuilt function. Please help

resultant image after using the masks resultant image after using the masks

Upvotes: 2

Views: 1896

Answers (5)

bionomical
bionomical

Reputation: 1

your resultant image is a subset of the second image.your first image probably overlaps too much with the second image...try using 30-50 percent overlap... I have a theory that more than that confuses the stitching algorithm

Upvotes: 0

Bill
Bill

Reputation: 700

I had this same exact error, which I solved by converting my each input image data type to float32.

dataset = dataset.astype(np.float32)

And then carry on as usual:

finder = cv2.detail_GraphCutSeamFinder("COST_COLOR")
seam_masks = finder.find(datasets, corners, masks)

Upvotes: 0

wyyqwqq
wyyqwqq

Reputation: 1

Your input image 'im1' and 'im2' should be normalized to [0,1] which is float type. By doing this, the error can be removed.

Upvotes: 0

Lukas Weber
Lukas Weber

Reputation: 721

The Python bindings of Graph Cut Seam Finder are corrupted at the moment. Please monitor this PR with a possible fix. I hope that it'll get merged soon.

Upvotes: 1

Bb Core
Bb Core

Reputation: 1

mask1 = np.full(bl.shape[:2], 255, dtype=np.uint8)

mask2 = np.full(br.shape[:2], 255, dtype=np.uint8)

This works for me. I used https://github.com/lukasalexanderweber/stitching . And find out that the type is np.uint8. If remove 'dtype=np.uint8', the masks will not be updated.

Upvotes: 0

Related Questions