Commit 025514ba52b1d8789832b79bcba44bde87919d5b
1 parent
630e440a
msvc compile fix
Showing
1 changed file
with
23 additions
and
28 deletions
openbr/plugins/metadata/majorityvoting.cpp
| ... | ... | @@ -42,7 +42,6 @@ class MajorityVotingTransform : public UntrainableMetadataTransform |
| 42 | 42 | BR_PROPERTY(QString, outputKey, "MajorityVoting") |
| 43 | 43 | BR_PROPERTY(float, thresh, -1) |
| 44 | 44 | |
| 45 | - | |
| 46 | 45 | void projectMetadata(const File &src, File &dst) const |
| 47 | 46 | { |
| 48 | 47 | dst = src; |
| ... | ... | @@ -57,48 +56,44 @@ class MajorityVotingTransform : public UntrainableMetadataTransform |
| 57 | 56 | return; |
| 58 | 57 | } |
| 59 | 58 | } |
| 60 | - int classCount[numClasses]; //= {0}; | |
| 61 | - for (int i = 0; i < numClasses; i++){ | |
| 62 | - classCount[i] = 0; | |
| 63 | - } | |
| 59 | + QVector<int> classCount(numClasses, 0); | |
| 64 | 60 | for (int c = 0; c < scores.size(); c+= numClasses){ |
| 65 | - if(numClasses == 2 and thresh != -1){ | |
| 66 | - if (scores[c] > thresh) | |
| 67 | - classCount[0]++; | |
| 68 | - else | |
| 69 | - classCount[1]++; | |
| 70 | - } else { | |
| 71 | - int highestScoringClass = 0; | |
| 72 | - float highestScore = scores[c]; | |
| 73 | - for (int b = 1; b < numClasses; b++){ | |
| 61 | + if(numClasses == 2 and thresh != -1){ | |
| 62 | + if (scores[c] > thresh) | |
| 63 | + classCount[0]++; | |
| 64 | + else | |
| 65 | + classCount[1]++; | |
| 66 | + } else { | |
| 67 | + int highestScoringClass = 0; | |
| 68 | + float highestScore = scores[c]; | |
| 69 | + for (int b = 1; b < numClasses; b++){ | |
| 74 | 70 | if (scores[c+b] > highestScore){ |
| 75 | - highestScore = scores[c+b]; | |
| 76 | - highestScoringClass = b; | |
| 71 | + highestScore = scores[c+b]; | |
| 72 | + highestScoringClass = b; | |
| 77 | 73 | } |
| 78 | - } | |
| 79 | - classCount[highestScoringClass]++; | |
| 80 | - } | |
| 74 | + } | |
| 75 | + classCount[highestScoringClass]++; | |
| 76 | + } | |
| 81 | 77 | } |
| 82 | - int largestIndex = getIndexOfLargestElement(classCount,numClasses); | |
| 78 | + int largestIndex = getIndexOfLargestElement(classCount); | |
| 83 | 79 | |
| 84 | - QList<int> output = QList<int>(); | |
| 85 | - for(int i=0; i <numClasses; i++){ | |
| 86 | - if(i == largestIndex) output.append(1); | |
| 87 | - else output.append(0); | |
| 88 | - } | |
| 80 | + QList<int> output = QList<int>(); | |
| 81 | + for(int i=0; i <numClasses; i++){ | |
| 82 | + if(i == largestIndex) output.append(1); | |
| 83 | + else output.append(0); | |
| 84 | + } | |
| 89 | 85 | dst.setList(outputKey,output); |
| 90 | 86 | } |
| 91 | 87 | |
| 92 | - int getIndexOfLargestElement(int arr[], int numClasses) const { | |
| 88 | + int getIndexOfLargestElement(const QVector<int> &arr) const { | |
| 93 | 89 | int largestIndex = 0; |
| 94 | - for (int i = largestIndex; i < numClasses; i++) { | |
| 90 | + for (int i = largestIndex; i < arr.size(); i++) { | |
| 95 | 91 | if (arr[largestIndex] <= arr[i]) { |
| 96 | 92 | largestIndex = i; |
| 97 | 93 | } |
| 98 | 94 | } |
| 99 | 95 | return largestIndex; |
| 100 | 96 | } |
| 101 | - | |
| 102 | 97 | }; |
| 103 | 98 | |
| 104 | 99 | BR_REGISTER(Transform, MajorityVotingTransform) | ... | ... |