Display image using condition statement

Hello, I have question to ask, i’m using if condition to display an image using opencv.
is it possible to close the image according to the condition in opencv. I try with the waitkey but it’s not following my if condition. does anyone have idea how to solve this.

Thank you

it might help, if you can

  • describe your “condition” better
  • show us our current attempt

Thank you for your reply.

I have data from arduino and send the data to python via serial port. Example as below:

x = float(splitPacket[0])
if (-3<=x<-2):
img = cv2.imread(“image/pic1.jpg”)
imgResized = cv2.resize(img,(1200,650))
cv2.imshow(“output”,imgResized)
cv2.waitKey(0)
cv2.destroyAllWindows()