Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. void testFunc(bool flag){
  2. cv::Size testSize = cv::Size(500, 500);
  3. cv::Mat testMat = cv::Mat::zeros(testSize, CV_32F);
  4. cout << testMat.cols << endl;
  5. cout << testMat.rows << endl;
  6. for (int i = 0; i < testMat.cols; i++){
  7. for (int j = 0; j < testMat.rows; j++){
  8. if (flag){
  9. testMat.at<float>(j, i) = ((float)i + (float)j*500.0f) / (float)testSize.area();
  10. }
  11. else{
  12. if (50 < i && i < 300 && 50 < j && j < 300){
  13. testMat.at<float>(j, i) = ((float)i + (float)j*500.0f) / (float)testSize.area();
  14. }
  15. else{
  16. testMat.at<float>(j, i) = 0.0f;
  17. }
  18. }
  19. }
  20. }
  21. cv::imshow("testmat",testMat);
  22. // 1行のArrayにする
  23. cv::Mat testArray = testMat.reshape(1, 1);
  24. cv::Mat testScoreIndices;
  25. cv::sortIdx(testArray, testScoreIndices, SORT_EVERY_ROW + SORT_DESCENDING);
  26.  
  27.  
  28. cv::Mat imgScore = cv::Mat::zeros(testSize, CV_8U);
  29. int channel_num = 1;
  30. int stride = testSize.width * channel_num;
  31. int threshold = testScoreIndices.cols * 0.2;
  32. cout << threshold << endl;
  33. for (int Y = 0; Y < testSize.height; Y++){
  34. for (int X = 0; X < testSize.width; X++){
  35. int CHANNEL = 0;
  36. int *scoreIndex = (int *)testScoreIndices.data;
  37. if (scoreIndex[Y * stride + X * channel_num + CHANNEL] <= threshold){
  38. imgScore.at<unsigned char>(Y, X) = 255;
  39. }
  40. }
  41. }
  42. cv::imshow("score", imgScore);
  43.  
  44. cv::waitKey(0);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement