Python
NumPy
1. np.where
std::vector<std::vector<int>> np_where(cv::Mat img_bin, int val)
{
std::vector<std::vector<int>> res;
std::vector<int> res_row;
std::vector<int> res_col;
uchar pixel;
for (int row = 0; row < img_bin.rows; row++)
{
for (int col = 0; col < img_bin.cols; col++)
{
//pixel = img_bin.at<uchar>(row, col);
pixel = img_bin.ptr<uchar>(row)[col];
if (pixel == val)
{
res_row.push_back(row);
res_col.push_back(col);
}
}
}
res.push_back(res_row);
res.push_back(res_col);
return res;
}
PyTorch
1. softmax
没有必要,可以在网络最后加上softmax再进行模型转换