I have a camera that is sending the image data to my computer. From there my python script puts the 8bit color info (black and white; ranging from 0 - black - to 255 - white) into a numpy array. The array is 2D, first dimension up to 384 and second dimensions up to 288 Displaying this with a openCV window works great and the live video is more than 24fps.
My aim now is to manipulate the image, so that the live video displays any color value below 200 as 0 (completely black) and any color value above 200 as 255 (completely white). However, my code right now only gives me about 3fps.
My code is doing the following:
- save the image that comes from the camera in a numpy array
- open the first
forloop to iterate through the x values - in that first
forloop iterate through the secondforloop with the y values - check each color value for every pixel and check if it is above 200 or not
- depending on the
ifclause make the color value 0 or 255 - display the new image
This is the decisive part in the code:
processedImage = frame
i = 0
for i in range(0, displayedWidth):
ii = 0
for ii in range(0, displayedHeight):
if frame[ii, i] > 200:
processedImage[ii, i] = 255
else:
processedImage[ii, i] = 0
cv2.imshow("LiveVideo", processedImage)
I read here that for loops are faster than while loops, but it didn't improve the code's speed significantly, which is why I assume the rewriting of the processedImage takes too long.
Is there a way to make the whole process faster?
Thanks for any answers!