1

I would like to rotate an image in OpenCV (I'm currently doing it this way image manipulation SO answer) but would like to specify the colour used to fill the gaps created by the rotation - by default, it's black (see below)

enter image description here

How could this be done?

Community
  • 1
  • 1
James
  • 30,496
  • 19
  • 86
  • 113

1 Answers1

2

I think the answer lies in the official doc:

C: void cvWarpAffine(const CvArr* src, CvArr* dst, const CvMat* map_matrix, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, CvScalar fillval=cvScalarAll(0) )

where

CvScalar fillval=cvScalarAll(0) specifies the fill color of the "gap".

Just specify the fillval with a color scalar when calling this function.

SolessChong
  • 3,370
  • 8
  • 40
  • 67
  • Why are you referencing the obsolete C API, instead of C++? – jnovacho Jun 25 '13 at 12:54
  • 1
    Worked like a charm, thanks! As @jnovacho pointed out, you are using the old C API - but the same argument still exists in cv2: `void warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar()` – James Jun 25 '13 at 13:09