[問題] OpenCV讀取像素值的問題請求解救。

看板C_and_CPP (C/C++)作者 (蟹子)時間14年前 (2011/08/22 17:12), 編輯推噓2(206)
留言8則, 3人參與, 最新討論串1/1
開發平台(Platform): Linux + OpenCV 2.1 額外使用到的函數庫(Library Used): OpenCV 問題(Question):讀取的每一個像素值不正確。 餵入的資料(Input): uchar* water_pixel;(全域) for(row=0;row<water_img->height;row++) { //printf("the %d row : ",row); for(col=0;col<water_img->width;col++) { water_pixel = (uchar*)(water_img->imageData+row*water_img->widthStep + col); printf("%d this is upper %3d\n ",total, water_pixel[total]); total+1; } } printf("water pixel for 11 is = %3d\n", water_pixel[10]); printf("water pixel for 3000 is = %3d\n", water_pixel[2999]); int x, y, z; for ( x = 0, y=0,z =0; x < water_size; x++ ) { printf("%d Water_pixel %d = %d\n",z, x, water_pixel[y]); z++; y+1; } 預期的正確結果(Expected Output): 小弟的像素值為,pixel 0 = 251, pixel 11 = 238, pixel 3000 = 195 錯誤結果(Wrong Output): 錯誤結果出來為,piexel 11 = 0, pixel 3000 = 248, 全部的pixel(for迴圈的) 都是255,全部都不是我的像素值。 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): 懇請神人協助小弟,小弟找不到問題處。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.232.205.45

08/22 17:27, , 1F
Water_pixel = blabla 這一行 W_p是不是也要加坐標位置?
08/22 17:27, 1F

08/22 18:26, , 2F
加座標噢,我加看然後執行看看,再給大大知道結果噢~謝謝
08/22 18:26, 2F

08/22 22:52, , 3F
water_pixel這個指標在跑完for迴圈後,就指向圖片的最後一
08/22 22:52, 3F

08/22 22:53, , 4F
個相素了
08/22 22:53, 4F

08/22 22:53, , 5F
你想要拿哪一個相素,就只要
08/22 22:53, 5F

08/22 22:54, , 6F
water_pixel = (uchar*)(water_img->imageData+row*water_
08/22 22:54, 6F

08/22 22:55, , 7F
img->widthStep +col);這行
08/22 22:55, 7F

08/22 22:56, , 8F
接下來用*water_pixel或water_pixel[0]取得值
08/22 22:56, 8F
文章代碼(AID): #1EKXs1TX (C_and_CPP)
文章代碼(AID): #1EKXs1TX (C_and_CPP)