# Display image using condition statement

**URL:** <https://forum.opencv.org/t/display-image-using-condition-statement/9627>\
**Category:** Uncategorized\
**Tags:** programming\
**Created:** [July 26, 2022, 1:15am UTC](https://forum.opencv.org/t/display-image-using-condition-statement/9627 "2022-07-26T01:15:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nur92](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@nur92](https://forum.opencv.org/u/nur92)\
**Post date:** [July 26, 2022, 1:15am UTC](https://forum.opencv.org/t/display-image-using-condition-statement/9627/1 "2022-07-26T01:15:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 27, 2022, 11:05am UTC](https://forum.opencv.org/t/display-image-using-condition-statement/9627/2 "2022-07-27T11:05:06Z")

</div>

it might help, if you can

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

---

<div class="post-metadata">

**Author:** ![nur92](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@nur92](https://forum.opencv.org/u/nur92)\
**Post date:** [July 27, 2022, 11:24pm UTC](https://forum.opencv.org/t/display-image-using-condition-statement/9627/3 "2022-07-27T23:24:58Z")

</div>

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()
