I am coding a python method that uses OpenCV to process some images from the camera and compare pixel by pixel the image with some parameters and, depending on these parameters, put that pixel to zero. The piece of code that does the following:
while True:
ret, frame = cap.read()
for row in range(rows):
for col in range(cols):
b1 = (frame[row][col][:] < Nsigma2[row][col][:]).all();
b2 = (frame[row][col][:] > Psigma2[row][col][:]).all();
if not b1 and not b2:
frame[row][col][:] = [0,0,0];
cv.imshow('frame',frame)
if cv.waitKey(15) & 0xFF == ord('q'):
break
Besides the correctness or lack of the algorithm itself, is this the right way to move and access matrices numpy? But it is very slow. I think the slowest direction is the third component of the matrices, which I refer to in the inner loop, but I have not found a better way to do this. I'm not very used to Python, so is this normal and expected such slow performance?
Genís