Repository navigation
samples: Add C++ implementation of digits.py - #14260
Conversation
ca38319 to
17a15fd
Compare
| warpAffine(img, deskewed_img, M, Size(SZ, SZ), WARP_INVERSE_MAP | INTER_LINEAR); | ||
| } | ||
|
|
||
| class StatModel |
There was a problem hiding this comment.
isn't this redundant (and misleading) ?
there's already a ml::StatModel, a ml::KNearest and a ml::SVM
There was a problem hiding this comment.
I copied the Python implementation of this sample, which wraps all three classes, but I agree that it's redundant.
|
|
||
| void load(const char* fn) | ||
| { | ||
| _model->load<ml::KNearest>(fn); |
There was a problem hiding this comment.
this won't work (same problem with SVM).
Algorithm::load() is a static method, and returns a new instance,
| cout << "preprocessing..." << endl; | ||
|
|
||
| // shuffle digits | ||
| shuffle(digits, labels); |
There was a problem hiding this comment.
not sure about KNearest, but the SVM will do internal shuffeling already
| " ./digits\n" << endl; | ||
| } | ||
|
|
||
| static void split2d(Mat& image, Size cell_size, vector<Mat>& cells) |
There was a problem hiding this comment.
Here and below, please use "const reference" for input parameters:
const Mat&const std::vector<...>&const Ptr<...>&
| { | ||
| for (int j = 0; j < width; j += sx) | ||
| { | ||
| cells.push_back(image(Rect(j, i, sx, sy)).clone()); |
There was a problem hiding this comment.
.clone()
Do we need this? Is it required?
| for (int j = 0; j < 10; j++) | ||
| { | ||
| int val = confusion[i][j]; | ||
| cout << (val / 10 > 0 ? "" : " ") << val << ' '; |
There was a problem hiding this comment.
We can use this here:
cout << cv::format("%2d ", val);
17a15fd to
86561fe
Compare
alalek
left a comment
There was a problem hiding this comment.
@allanrodriguez Thank you for the contribution 👍
@berak Thank you for reviewing!
Currently, only a Python implementation of the SVM and KNearest digit recognition sample exists. This pull request adds a C++ implementation.