當我試圖畫一個箭頭與OpenCV的3.2丟失:像素的箭頭提示使用抗鋸齒
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
int main()
{
Mat image(480, 640, CV_8UC3, Scalar(255, 255, 255)); //White background
Point from(320, 240); //Middle
Point to(639, 240); //Right border
arrowedLine(image, from, to, Vec3b(0, 0, 0), 1, LINE_AA, 0, 0.1);
imshow("Arrow", image);
waitKey(0);
return 0;
}
用箭頭畫出,但在尖端的一些像素丟失:
爲了更精確,兩列像素沒有正確着色(縮放):
如果我禁用抗鋸齒,也就是說,如果我用
arrowedLine(image, from, to, Vec3b(0, 0, 0), 1, LINE_8, 0, 0.1);
代替(注意LINE_8代替LINE_AA),像素都在那裏,雖然沒有抗鋸齒:
我意識到抗鋸齒可能依賴於相鄰像素,但看起來很奇怪的是,像素在邊界處根本不被繪製,而不是在沒有抗鋸齒的情況下繪製。有沒有解決這個問題的方法?
增加X座標,例如,到640或641)使問題變得更糟,即更多的箭頭像素消失,而尖端仍然缺少近兩個完整的像素列。
擴展和裁剪圖像將解決相鄰像素問題,但在我最初的使用案例中,出現問題的位置,我無法放大我的圖像,即其大小必須保持不變。
你可以在邊界處有「之前」和「之後」的平均值 –
@huseyintugrulbuyukisik:你的意思是我在有AA和沒有AA的情況下繪製箭頭,並取兩個受影響列的平均值? –
我的意思是隻有邊界,而不是整個圖像 –