3
A
回答
1
Sets and Sparse Matrices
,23頁:
在OpenCV的稀疏矩陣使用CVSET用於存儲元件。
CvSparseMat* get_color_map(const IplImage* img)
{
int dims[] = { 256, 256, 256 };
CvSparseMat* cmap = cvCreateSparseMat(3, dims, CV_32SC1);
for(int i = 0; i < img->height; i++) for(int j = 0; j < img->width; j++)
{
uchar* ptr=&CV_IMAGE_ELEM(img,uchar,i,j*3);
int idx[] = {ptr[0],ptr[1],ptr[2]};
((int*)cvPtrND(cmap,idx))[0]++;
}
// print the map
CvSparseMatIterator it;
for(CvSparseNode *node = cvInitSparseMatIterator(mat, &iterator);
node != 0; node = cvGetNextSparseNode(&iterator))
{
int* idx = CV_NODE_IDX(cmap,node);
int count=*(int*)CV_NODE_VAL(cmap,idx);
printf(「(b=%d,g=%d,r=%d): %d\n」, idx[0], idx[1], idx[2], count);
}
return cmap;
}
6
使用C++接口可能更合適。請注意,文檔[1]中的示例代碼缺少模運算,因此失敗。
const int dims = 2;
int size[] = {3, 20}; // rows and columns if in two dimensions
SparseMat sparse_mat(dims, size, CV_32F);
for(int i = 0; i < 1000; i++) {
// create a random index in dims dimensions
int idx[dims];
for(int k = 0; k < dims; k++)
idx[k] = rand() % size[k];
sparse_mat.ref<float>(idx) += 1.f;
}
cout << "bottom right element @ (2,19) = " << sparse_mat.ref<float>(2,19) << "\n";
Mat dense;
sparse_mat.convertTo(dense, CV_32F);
cout << dense;
給出以下輸出
bottom right element @ (2,19) = 19
[9, 23, 13, 26, 18, 13, 18, 15, 13, 17, 13, 18, 19, 6, 20, 20, 12, 15, 15, 15;
17, 17, 14, 16, 12, 14, 17, 15, 15, 18, 24, 18, 13, 22, 18, 11, 18, 22, 17, 15;
19, 16, 14, 10, 18, 19, 10, 17, 18, 15, 24, 22, 18, 18, 18, 23, 21, 16, 14, 19]
[1]的OpenCV參考手冊。版本2.4.3。 2012,p。 46.
相關問題
- 1. 如何結合使用java的小馬庫的兩個sparsematrix?
- 2. 如何獲得sparseMatrix的零零索引?
- 3. 如何使用OpenCV triangulatePoints
- 4. 如何使用opencv flann :: Index?
- 5. 如何使用OpenCV的
- 6. 如何使用OpenCV與Qt5
- 7. 如何使用OpenCV MatchTemplate?
- 8. 如何使用brython使用OpenCV python庫
- 9. 如何使熱圖使用python和OpenCV
- 10. 如何使用OpenCV的用VB.NET 2008
- 11. 如何在opencv中使用fred的imagemagick textcleaner腳本C++/opencv java?
- 12. 如何混合使用OpenCV 1.0和OpenCV 2.0
- 13. 如何在opencv中使用cvDCT()?
- 14. 如何配置Makefile以使用OpenCV
- 15. 如何檢測使用的OpenCV +蟒蛇
- 16. 如何使用OpenCV cvProjectPoints2函數
- 17. 如何在opencv 2.4中使用SIFT
- 18. 如何使用opencv墊預留?與push_back
- 19. 如何使用OpenCV的相機
- 20. 如何在Java中使用opencv BOWKMeansTrainer?
- 21. 如何使用opencv創建HDR圖像
- 22. 如何在Python中使用OpenCV cornerSubPix()?
- 23. Python OpenCV 3:如何使用cv2.CV_COMP_HELLINGER
- 24. 如何使用OpenCV的蟒蛇
- 25. 如何在Android NDK中使用OpenCV BOWImgDescriptorExtractor?
- 26. 如何在OpenCV Android中使用createTrackBar()?
- 27. 如何使用CV :: createButton原型OpenCV中
- 28. 如何在iOS中使用OpenCV?
- 29. 如何使用TBB構建OpenCV?
- 30. 如何使用OpenCV執行LU分解?