Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void testFunc(bool flag){
- cv::Size testSize = cv::Size(500, 500);
- cv::Mat testMat = cv::Mat::zeros(testSize, CV_32F);
- cout << testMat.cols << endl;
- cout << testMat.rows << endl;
- for (int i = 0; i < testMat.cols; i++){
- for (int j = 0; j < testMat.rows; j++){
- if (flag){
- testMat.at<float>(j, i) = ((float)i + (float)j*500.0f) / (float)testSize.area();
- }
- else{
- if (50 < i && i < 300 && 50 < j && j < 300){
- testMat.at<float>(j, i) = ((float)i + (float)j*500.0f) / (float)testSize.area();
- }
- else{
- testMat.at<float>(j, i) = 0.0f;
- }
- }
- }
- }
- cv::imshow("testmat",testMat);
- // 1行のArrayにする
- cv::Mat testArray = testMat.reshape(1, 1);
- cv::Mat testScoreIndices;
- cv::sortIdx(testArray, testScoreIndices, SORT_EVERY_ROW + SORT_DESCENDING);
- cv::Mat imgScore = cv::Mat::zeros(testSize, CV_8U);
- int channel_num = 1;
- int stride = testSize.width * channel_num;
- int threshold = testScoreIndices.cols * 0.2;
- cout << threshold << endl;
- for (int Y = 0; Y < testSize.height; Y++){
- for (int X = 0; X < testSize.width; X++){
- int CHANNEL = 0;
- int *scoreIndex = (int *)testScoreIndices.data;
- if (scoreIndex[Y * stride + X * channel_num + CHANNEL] <= threshold){
- imgScore.at<unsigned char>(Y, X) = 255;
- }
- }
- }
- cv::imshow("score", imgScore);
- cv::waitKey(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement