Arun Subraminion
Arun Subraminion

Reputation: 89

mentioning interpolation method in cv2.warpaffine()

How can I use the bicubic interpolation method in the cv2.warpAffine() method? I am trying to rotate an image through a non-center point.

import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('1.jpg',0)
rows,cols = img.shape
M = cv2.getRotationMatrix2D((cols/2,rows/2),-40,1) 
dst = cv2.warpAffine(img,M,(cols,rows),flags=CV_INTER_CUBIC)
#cv2.Resize(src, dst, interpolation=CV_INTER_CUBIC)
plt.imshow(dst)

With this I get NameError: name 'CV_INTER_CUBIC' is not defined

Upvotes: 0

Views: 6924

Answers (1)

alkasm
alkasm

Reputation: 23012

Most of the constants in OpenCV that have a prepending CV_ have them removed in the newer versions and they just become CONSTANT_VALUE instead of CV_CONSTANT_VALUE. For example, when you're changing colorspace from BGR to HSV, you use cv2.COLOR_BGR2HSV instead of cv2.CV_COLOR_BGR2HSV which you would use in C++. However even for C++ the constants for interpolation methods have had the prepending CV_ removed, so it's also INTER_CUBIC and not CV_INTER_CUBIC (although the latter is still defined). See for e.g. the docs for resize() which the docs for warpAffine() reference for the interpolation methods.

The basic separation is that the CV_ constants come from the original C API. You can see all the C API constants definitions here. And you can see how the prepending CV_ was removed from the constants in the newer API by browsing through the documentation, like here for e.g.

So anyways, the answer to the question is to use the flag cv2.INTER_CUBIC.

Upvotes: 1

Related Questions