0

I have a camera that takes photos in two different qualities: "cam-lo.jpg":LOW quality that should always be requested to get photos every 0.2 seconds(getting photos fastly gives the effect of a video) and "cam-hi.jpg":HIGH quality. If the distance variable is less or equal to 40, I have to request "http://192.164.1.39/cam-hi.jpg" and stop requesting for the Low-Quality one until I get the high quality picture and do processing with it. For this purpose I try to stop the other thread with python-condition as below:

if distance<=40:
    while(True):
        **cond.acquire()**
        a="stop"
        for i in range(5):
            response=urllib.request.urlopen("http://192.164.1.39/cam-hi.jpg")
            img=Image.open(BytesIO(response.read(100000)))
            try:
                output=str(i)+".jpg"
                img.save(output)
                img.save('C:/Users/hi/Desktop/savings/'+"high.jpg", 'JPEG')
            except IOError:
                print("cannot convert",infile)
            a="finished"
            print(a)
            # AFTER HERE, THERE İS A LONG CODE FOR IMAGE PROCESSING THAT THE PROGRAM CANT REACH
            #code for image processing.......
            cond.notify()
            cond.release()


def CamRequest():
    global a
    while(True):
        cond.acquire()
        if(a=="stop"):
           print(a)
           cond.wait()
           cond.notify()
           cond.release()
           response=urllib.request.urlopen("http://192.164.1.39/cam-lo.jpg")
           img2=Image.open(BytesIO(response.read(100000)))
           img2.save('C:/Users/hi/Desktop/savings/'+"1.jpg", 'JPEG')
           time.sleep(0.2)
           print(a)

This works fine until the line where I take the high quality picture but cant do anything with it in sense processing because the program stops there(I mean it just "waits") . I looked also for "async requests" but in my case I have to use urllib since the response is only an image. It would be great if I could process the high quality images after I have taken them while the low quality images are still being requested.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • My [answer](https://stackoverflow.com/a/15734837/355230) to a question about starting and stopping threads may be helpful. – martineau May 08 '20 at 20:32
  • Thank you . But Could you maybe tell me how this can be carried to my problem? i cant recognize how to modify your code. Im sorry but i would really be thankful. – Engineering12 May 08 '20 at 22:14
  • There's way too much left out of your question — it's not even clear whether or how you're using threading — for me to post an answer, sorry. – martineau May 09 '20 at 00:43

0 Answers0