0

here is the python code :

image = cv2.imread(img)        
gray=cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image1=np.zeros_like(image)
image1[:,:,0]=gray
image1[:,:,1]=gray  
image1[:,:,2]=gray

here is the C++ code:

 Mat img1 = imread(fn[i]);
 Mat greyMat1,greyMat2,greyMat3;
        
        
 cvtColor(img1, greyMat1, COLOR_BGR2GRAY);
 cvtColor(img1, greyMat2, COLOR_BGR2GRAY);
 cvtColor(img1, greyMat3, COLOR_BGR2GRAY);
 Mat out;
 Mat in[3] = { greyMat1,greyMat2,greyMat3};
 merge(in, 3, out);

when I feed my model with C++ grayscale converted images, I can't take the same confidence as Numpy(python) gives me. They must be the same because we are about the convert our model to DLL and all image preprocess must be done in C++ and must be the same with python confidences. How can I apply these python codes in C++ without the change of confidence values ?

Confidence : from opencv documentation

net.setInput(blob);
Mat prob = net.forward();
Point classIdPoint;
double confidence; //**confidence** **********************************
minMaxLoc(prob.reshape(1, 1), 0, &confidence, 0, &classIdPoint);
int classId = classIdPoint.x;
Muratali016
  • 13
  • 2
  • 8
  • What do you mean by `confidence`? Recognition rate? –  Feb 14 '22 at 22:19
  • @OrkhanAliyev You can find your answer in Question – Muratali016 Feb 14 '22 at 23:07
  • Copy it exactly then to get the most similar result. I mean, you do not use filled `Mat` in `c++` example though you did with `python`. Like `img.setTo(Scalar::all(0));` or `img = zeros(img.size(), img.type());`. And why not to use range based for loop for `cvtColor` in c++ example? It'll be easy and more similar to what you did with python. And use fixed vector instead of using fixed array for `Mat`. Once you done that, compare the results again. If they don't not return the exact values, you'll need to provide a bit more information. –  Feb 14 '22 at 23:24
  • @OrkhanAliyev thanks for these methods, now I created a `Mat` full of zeros in my source image size and I must fill these `Mat` s 3 dimensions(I made this Mat 3 dimensional) with grayscale `cvtColor(img1, greyMat1, COLOR_BGR2GRAY);` values. I researched but didn't find it. any suggestions? – Muratali016 Feb 15 '22 at 14:22

0 Answers0