[英]OpenCV Android wrong coordinates
我面臨Android的OpenCV的一個非常奇怪的問題:當我使用Mat.at訪問像素時,它在屏幕上給我提供了錯誤的像素:一個簡單的示例:
for( double y = (mat.rows - h) / 2 ; y < (mat.rows + h) / 2 ; y++ ) {
for( double x = (mat.cols - w) / 2; x < (mat.cols + w) / 2; x++ ) {
for( int c = 0; c < 3; c++ ) {
mat.at<Vec3b>(y,x)[c] =
saturate_cast<uchar>( 255 );
}
}
}
circle(mat, Point((mat.cols - w) / 2, (mat.rows - h) / 2), 10, Scalar(255,0,0,255));
circle(mat, Point((mat.cols + w) / 2, (mat.rows - h) / 2), 10, Scalar(255,0,0,255));
circle(mat, Point((mat.cols - w) / 2, (mat.rows + h) / 2), 10, Scalar(255,0,0,255));
circle(mat, Point((mat.cols + w) / 2, (mat.rows + h) / 2), 10, Scalar(255,0,0,255));
我應該使角與盒子對齊,但不與盒子對齊。 是否需要進行轉換才能訪問真實坐標?
您無需發布mat
的初始化,但它似乎已初始化為CV_8UC4
類型。 這意味着使用mat.at<cv::Vec3b>
訪問圖像會給您錯誤的像素位置。 即使您僅修改了三個通道,也必須使用at<cv::Vec4b>
訪問四通道圖像at<cv::Vec4b>
以提供正確的像素位置,如您的示例所示。
無關:建議不要將double
用作計數器變量類型。
這是一個遠景,但可能會對您有所幫助。 這是SDK仿真嗎? 我記得遇到問題。 當我在設備中嘗試代碼時,它就像是一種魅力。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.