Re: [問題] opencv Mat取直的問題
想請問
我試過了d大的兩個方式
但使用mat.at<uchar>(i,j)執行都會有閃退
有在大陸網站查到好像是opencv2.2本身的錯誤?
錯誤訊息如下
http://ppt.cc/LdFZ
主要是希望擷取下圖深度影像的某個區塊作處理
http://ppt.cc/6hjw
但使用
: Mat b;
: Mat a;
: for(k=0;k<20;k++)
: {
: for(j=0;j<20;j++)
: {
: b.data[k*b.cols+j] = a.data[k*a.cols+j];
: }
: }
結出來的圖繪變成下圖這樣= =
http://ppt.cc/9wxD
請問還有甚麼方法可以取得mat裡的值呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.136.146.60
推
08/27 14:58, , 1F
08/27 14:58, 1F
→
08/27 14:59, , 2F
08/27 14:59, 2F
→
08/27 15:10, , 3F
08/27 15:10, 3F
→
08/27 15:12, , 4F
08/27 15:12, 4F
→
08/27 15:40, , 5F
08/27 15:40, 5F
→
08/27 15:44, , 6F
08/27 15:44, 6F
→
08/27 15:59, , 7F
08/27 15:59, 7F
→
08/27 16:04, , 8F
08/27 16:04, 8F
→
08/27 16:05, , 9F
08/27 16:05, 9F
→
08/27 16:05, , 10F
08/27 16:05, 10F
→
08/27 16:09, , 11F
08/27 16:09, 11F
推
08/27 16:33, , 12F
08/27 16:33, 12F
→
08/27 17:34, , 13F
08/27 17:34, 13F
推
08/27 19:55, , 14F
08/27 19:55, 14F
→
08/28 09:26, , 15F
08/28 09:26, 15F
→
08/28 12:00, , 16F
08/28 12:00, 16F
→
08/28 13:57, , 17F
08/28 13:57, 17F
後來我看了core.hpp
裡面有一段寫到
The next important thing to learn about the matrix class is element access.
Here is how the matrix is stored.
The elements are stored in row-major order (row by row). The cv::Mat::data
member points to the first element of the first row,
cv::Mat::rows contains the number of matrix rows and cv::Mat::cols - the
number of matrix columns. There is yet another member,
cv::Mat::step that is used to actually compute address of a matrix
element. cv::Mat::step is needed because the matrix can be
a part of another matrix or because there can some padding space in the
end of each row for a proper alignment.
也有提到範例
*(b.data + (b.step*k + j*b.elemSize())) = 0;
用這樣的方式給值是可行的
要控制通道的話從b.step*k + j*b.elemSize() -1或-2去修改
※ 編輯: ddv70 來自: 140.136.146.60 (08/28 15:45)
※ 編輯: ddv70 來自: 140.136.146.60 (08/28 16:34)
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章