-1

Here i am trying to create a flask application that stream the webcam. I got the webcam streaming properly. And along the webcam streaming request, passing an another request for a multiplied frame value result (processed video) of the current streaming video.Which is not getting properly result but it's sending the request. And the problem is it's not share value between the class functions. In camera.py have 2 function getframe and GetBw which share a class variable self._image. But GetBw doesn't updated value of self._image.

Here is my flask application codes main.py & index.html

Rahul K P
  • 15,740
  • 4
  • 35
  • 52

1 Answers1

0

Here's the code that matters:

class MainObject():
    def gen(camera):
        while self.Status == True:
            self.frame = camera.get_frame()
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + self.frame + b'\r\n\r\n')

    def abc(camera):
        while self.Status == True:
            self.frame = camera.GetBw()
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + self.frame + b'\r\n\r\n')


class VideoCamera(object):
    def get_frame(self):
        success, image = self.video.read()
        ret, jpeg = cv2.imencode('.jpg', image)
        self.string = jpeg.tostring()
        self._image = image
        return jpeg.tostring()

    def GetBw(self):
        image = self._image
        ret, jpeg = cv2.imencode('.jpg', image)
        self.string = jpeg.tostring()
        return jpeg.tostring()

Your assertion that GetBw doesn't [get the] updated value of self._image is not true. In fact, it does get the updated value when you update it (within the same context).

But the problem is, in your abc generator, you're never causing video frames to be pulled from the camera. The line that pulls new frames from the camera is

success, image = self.video.read()

Which isn't anywhere that generator abc calls. So you end up repeatedly returning the same frame.

Instead, you probably just want GetBw to look like:

    def GetBw(self):
        success, image = self.video.read()
        ret, jpeg = cv2.imencode('.jpg', image)
        self.string = jpeg.tostring()
        return jpeg.tostring()
jedwards
  • 29,432
  • 3
  • 65
  • 92
  • But actually at a time we can only perform one video.read() function, if they work simultaneously it's will return a error v4l resource busy. – Rahul K P Apr 18 '15 at 07:05
  • @RahulKP Then you should write the frames to a file or database, and access them that way, see [this question](http://stackoverflow.com/questions/19277280/preserving-global-state-in-a-flask-application) or [this question](http://stackoverflow.com/questions/24429271/preserving-state-in-mod-wsgi-flask-application) – jedwards Apr 18 '15 at 07:08
  • I am done with 2 different class function thank you jedwards. – Rahul K P Apr 18 '15 at 12:18