1

I went through this beautifully explained Q/A and I want something similar into a much stripped down version of the code I found there which includes PyQt4 and qdarkstyle.

My code is as follows:

import pafy
import base64
import zmq
from threading import Thread
import cv2
import time


class IPCamera(object):
    def __init__(self, src=0):
        self.frame = None
        self.status = None
        self.capture = cv2.VideoCapture(src)
        self.capture.set(cv2.CAP_PROP_BUFFERSIZE, 2)
        self.FPS = 1/25
        self.FPS_MS = int(self.FPS * 1000)

        # Start frame retrieval thread
        self.thread = Thread(target=self.update, args=())
        self.thread.daemon = True
        self.thread.start()

    def update(self):
        while True:
            if self.capture.isOpened():
                (self.status, self.frame) = self.capture.read()
                # self.frame = cv2.resize(self.frame, (640, 480))  # resize the frame
            time.sleep(self.FPS)

    def show_frame(self):
        cv2.imshow('frame', self.frame)
        cv2.waitKey(self.FPS_MS)


if __name__ == '__main__':

    # Sample youtube video starts
    youtube_link = 'https://www.youtube.com/watch?v=QgaUKlAuqn8'
    vPafy = pafy.new(youtube_link)
    play = vPafy.getbest(preftype="mp4")
    src = play.url
    # Sample youtube video ends

    # Creating ZMQ context starts
    context = zmq.Context()
    footage_socket = context.socket(zmq.PUB)
    footage_socket.connect('tcp://localhost:5555')
    # cv2.namedWindow("Client Started!")
    # Creating ZMQ context ends

    threaded_camera = IPCamera(src)
    while threaded_camera.capture.isOpened():
        try:
            if threaded_camera.status is True:
                encoded, buffer = cv2.imencode('.jpg', threaded_camera.frame)
                jpg_as_text = base64.b64encode(buffer)
                footage_socket.send(jpg_as_text)
                # key = cv2.waitKey(1)
                # threaded_camera.show_frame()
                # if key == 27:  # exit on ESC
                #     break
            # else:
            #     break
        except AttributeError:
            pass

The above code is running fine, I want to implement the code from the Q/A on the aforementioned link with those libraries removed. Can you help me in that?

Aakash Basu
  • 1,689
  • 7
  • 28
  • 57
  • Aakash please add what you are aiming to do in the question. Any attempts to solve it with the reference code from the other link and where that is failing will also help. Otherwise this looks like a coding assignment help request. – mailtobash Sep 11 '20 at 00:19

0 Answers0