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