Performs per-element division of two arrays or a scalar by an array.
-
C++:
void
divide
(InputArray
src1, InputArray
src2, OutputArray
dst, double
scale=1, int
dtype=-1
)
-
C++:
void
divide
(double
scale, InputArray
src2, OutputArray
dst, int
dtype=-1
)
-
Python:
cv2.
divide
(src1, src2
[, dst
[, scale
[, dtype
]
]
]
) → dst
-
Python:
cv2.
divide
(scale, src2
[, dst
[, dtype
]
]
) → dst
-
C:
void
cvDiv
(const CvArr*
src1, const CvArr*
src2, CvArr*
dst, double
scale=1
)
-
Python:
cv.
Div
(src1, src2, dst, scale
) → None
-
Parameters: - src1 – First source array.
- src2 – Second source array of the same size and type as src1 .
- scale – Scalar factor.
- dst – Destination array of the same size and type as src2 .
- dtype – Optional depth of the destination array. If it is -1, dst will have depth src2.depth(). In case of an array-by-array division, you can only pass -1 when src1.depth()==src2.depth().
The functions divide divide one array by another:
or a scalar by an array when there is no src1 :
When src2(I) is zero, dst(I) will also be zero. Different channels of multi-channel arrays are processed independently.
同样,也能实现一个矩阵除以一个数,eg:
Mat concatenateMat(vector<Mat> &vec){
int height = vec[0].rows;
int width = vec[0].cols;
Mat res = Mat::zeros(height * width, vec.size(), CV_64FC1);
for(int i=0; i<vec.size(); i++){
Mat img(height, width, CV_64FC1);
vec[i].convertTo(img, CV_64FC1);
// reshape(int cn, int rows=0), cn is num of channels.
Mat ptmat = img.reshape(0, height * width);
Rect roi = cv::Rect(i, 0, ptmat.cols, ptmat.rows);
Mat subView = res(roi); //! res(roi) creates a matrix header for a part of the bigger matrix
ptmat.copyTo(subView);
}
divide(res, 255.0, res); //归一化到[0,1]范围
return res;
}