rows, cols = img1.shape[:2]
x = np.random.randint(0, 255, (w1, h1))
for i in range(rows):
for j in range(cols):
k = x[i, j]
我发现很难完成在Python OpenCV中找到两个图像的像素差异的代码。你能帮我解决正确的代码吗?
答案 0 :(得分:1)
In any case you should avoid loops over single pixels, but use operations which work on full images
You may want to have a look at the general OpenCV Python tutorial.
There is a chapter on arithmetic operation on images, this is what you are looking for: http://docs.opencv.org/3.1.0/d0/d86/tutorial_py_image_arithmetics.html#gsc.tab=0
The pdf version of the complete tutorial can be found here: https://media.readthedocs.org/pdf/opencv-python-tutroals/latest/opencv-python-tutroals.pdf