Set background of Python OpenCV warpPerspective -
when using warpperspective
scale image smaller, there black area around it. may like:
or
how make black borders white?
pts1 = np.float32([[minx,miny],[maxx,miny],[minx,maxy],[maxx,maxy]]) pts2 = np.float32([[minx + 20, miny + 20, [maxx - 20, miny - 20], [minx - 20, maxy + 20], [maxx + 20, maxy + 20]]) m = cv2.getperspectivetransform(pts1,pts2) dst = cv2.warpperspective(dst, m, (width, height))
how remove black borders after warpperspective
?
if @ documentation warpperspective
function online opencv documentation (http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html) says there parameter can give function specify constant border color:
cv2.warpperspective(src, m, dsize[, dst[, flags[, bordermode[, bordervalue]]]])
where
src – input image. dst – output image has size dsize , same type src . m – 3\times 3 transformation matrix. dsize – size of output image. flags – combination of interpolation methods (inter_linear or inter_nearest) , optional flag warp_inverse_map, sets m inverse transformation ( \texttt{dst}\rightarrow\texttt{src} ). bordermode – pixel extrapolation method (border_constant or border_replicate). bordervalue – value used in case of constant border; default, equals 0.
so like:
cv2.warpperspective(dist, m, (width, height), cv2.inter_linear, cv2.border_constant, 255)
should change border constant white color.
Comments
Post a Comment