I am unable to get cv::line to draw an anti-aliased line with CV_AA flags set. Here is example code to illustrate:
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
int main(int argc, char* argv[])
{
cv::Mat base(100, 100, CV_32F);
cv::Point2i p1(20, 20);
cv::Point2i p2(70, 90);
cv::line(base, p1, p2, cv::Scalar(1.0), 1, CV_AA); // 1 pixel thick, CV_AA == Anti-aliased flag
cv::namedWindow("line test", CV_NORMAL);
cv::imshow("line test", base);
cv::waitKey(0);
return 0;
}
I have tried using cv::Point2d instead of cv::Point2i and found no difference. (i == integer, d == double) I have also tried making the pixel width larger than 1, but there is still no AA.
However, this does work with a CV_8U (8-bit unsigned) image, as opposed to CV_32F (32-bit float) image that I have here. (For CV_8U, you must pass cv::Scalar(255) instead of cv::Scalar(1.0) into the line function to compare)
I suppose a current work-around would be to start with a CV_8U image then convert, but is there a straightforward way to do it with just an CV_32F image that doesn't require me to write my own anti-aliasing function?
Am I missing something?
OpenCV docs: cv::line reference
