diff --git a/person_detection/person_detection.py b/person_detection/person_detection.py
index 702f9f8..6f56a6f 100644
--- a/person_detection/person_detection.py
+++ b/person_detection/person_detection.py
@@ -13,6 +13,7 @@
 from argparse import ArgumentParser, SUPPRESS
 from imutils import build_montages
 from openvino.inference_engine import IECore
+from base_camera import BaseCamera
 
 
 def build_argparser():
@@ -40,152 +41,164 @@
     return parser
 
 
-def main():
-    log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
-    args = build_argparser().parse_args()
-    model_xml = args.model
-    model_bin = os.path.splitext(model_xml)[0] + ".bin"
+class Camera(BaseCamera):
 
-    # Read IR
-    log.info("Reading IR...")
-    net = IECore().read_network(model=model_xml, weights=model_bin)
+    def __init__(self, args):
+        log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
+        model_xml = args.model
+        model_bin = os.path.splitext(model_xml)[0] + ".bin"
 
-    assert len(net.inputs.keys()) == 1, "Demo supports only single input topologies"
-    assert len(net.outputs) == 1, "Demo supports only single output topologies"
-    input_blob = next(iter(net.inputs))
-    out_blob = next(iter(net.outputs))
+        # Read IR
+        log.info("Reading IR...")
+        net = IECore().read_network(model=model_xml, weights=model_bin)
 
-    log.info("Loading IR to the plugin...")
-    exec_net = IECore().load_network(network=net, device_name=args.device, num_requests=2)
-    # Read and pre-process input image
-    n, c, h, w = net.inputs[input_blob].shape
-    del net
-    if args.input == 'cam':
-        input_stream = 0
-    elif args.input == 'gstreamer':
-        # gst rtp sink
-        input_stream = 'udpsrc port=5000 caps = " application/x-rtp, encoding-name=JPEG,payload=26" ! rtpjpegdepay ! decodebin ! videoconvert ! appsink'
-        #input_stream = 'udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! appsink'
-    else:
-        input_stream = args.input
-        assert os.path.isfile(args.input), "Specified input file doesn't exist"
+        assert len(net.inputs.keys()) == 1, "Demo supports only single input topologies"
+        assert len(net.outputs) == 1, "Demo supports only single output topologies"
+        self.input_blob = next(iter(net.inputs))
+        self.out_blob = next(iter(net.outputs))
 
-    if input_stream == 'gstreamer':
-        cap = cv2.VideoCapture(input_stream, cv2.CAP_GSTREAMER)
-    else:
-        cap = cv2.VideoCapture(input_stream)
-
-    if args.labels:
-        with open(args.labels, 'r') as f:
-            labels_map = [x.strip() for x in f]
-    else:
-        labels_map = None
-
-    cur_request_id = 0
-    next_request_id = 1
-
-    log.info("Starting inference in async mode...")
-    log.info("To switch between sync and async modes press Tab button")
-    log.info("To stop the demo execution press Esc button")
-
-    # Async doesn't work if True
-    # Request issues = Runtime Error: [REQUEST BUSY]
-    is_async_mode = False
-    #is_async_mode = True
-    render_time = 0
-    ret, frame = cap.read()
-
-    frameList = []
-
-    print("To close the application, press 'CTRL+C' or any key with focus on the output window")
-
-    while True:
-        if is_async_mode:
-            ret, next_frame = cap.read()
+        log.info("Loading IR to the plugin...")
+        self.exec_net = IECore().load_network(network=net, device_name=args.device, num_requests=2)
+        # Read and pre-process input image
+        self.n, self.c, self.h, self.w = net.inputs[self.input_blob].shape
+        del net
+        if args.input == 'cam':
+            input_stream = 0
+        elif args.input == 'gstreamer':
+            # gst rtp sink
+            input_stream = 'udpsrc port=5000 caps = " application/x-rtp, encoding-name=JPEG,payload=26" ! rtpjpegdepay ! decodebin ! videoconvert ! appsink'
+            #input_stream = 'udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! appsink'
         else:
-            ret, frame = cap.read()
-        if not ret:
-            break
-        initial_w = cap.get(3)
-        initial_h = cap.get(4)
+            input_stream = args.input
+            assert os.path.isfile(args.input), "Specified input file doesn't exist"
 
-        # Main sync point:
-        # in the truly Async mode we start the NEXT infer request, while waiting for the CURRENT to complete
-        # in the regular mode we start the CURRENT request and immediately wait for it's completion
-        inf_start = time.time()
-        if is_async_mode:
-            if ret:
-                in_frame = cv2.resize(next_frame, (w, h))
-                in_frame = in_frame.transpose((2, 0, 1))  # Change data layout from HWC to CHW
-                in_frame = in_frame.reshape((n, c, h, w))
-                exec_net.start_async(request_id=next_request_id, inputs={input_blob: in_frame})
+        if input_stream == 'gstreamer':
+            self.cap = cv2.VideoCapture(input_stream, cv2.CAP_GSTREAMER)
         else:
-            if ret:
-                in_frame = cv2.resize(frame, (w, h))
-                in_frame = in_frame.transpose((2, 0, 1))  # Change data layout from HWC to CHW
-                in_frame = in_frame.reshape((n, c, h, w))
-                exec_net.start_async(request_id=cur_request_id, inputs={input_blob: in_frame})
+            self.cap = cv2.VideoCapture(input_stream)
 
-        if exec_net.requests[cur_request_id].wait(-1) == 0:
-            inf_end = time.time()
-            det_time = inf_end - inf_start
+        if args.labels:
+            with open(args.labels, 'r') as f:
+                self.labels_map = [x.strip() for x in f]
+        else:
+            self.labels_map = None
 
-            # Parse detection results of the current request
-            res = exec_net.requests[cur_request_id].outputs[out_blob]
+        self.args = args
 
-            for obj in res[0][0]:
-                # Draw only objects when probability more than specified threshold
-                if obj[2] > args.prob_threshold:
-                    xmin = int(obj[3] * initial_w)
-                    ymin = int(obj[4] * initial_h)
-                    xmax = int(obj[5] * initial_w)
-                    ymax = int(obj[6] * initial_h)
-                    class_id = int(obj[1])
-                    # Draw box and label\class_id
-                    color = (min(class_id * 12.5, 255), min(class_id * 7, 255), min(class_id * 5, 255))
-                    cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color, 2)
-                    det_label = labels_map[class_id] if labels_map else str(class_id)
-                    cv2.putText(frame, det_label + ' ' + str(round(obj[2] * 100, 1)) + ' %', (xmin, ymin - 7),
-                                cv2.FONT_HERSHEY_COMPLEX, 0.6, color, 1)
-                    print('Object detected, class_id:', class_id, 'probability:', obj[2], 'xmin:', xmin, 'ymin:', ymin,
-                          'xmax:', xmax, 'ymax:', ymax)
+        super(Camera, self).__init__()
 
-            # Draw performance stats
-            inf_time_message = "Inference time: Not applicable for async mode" if is_async_mode else \
-                "Inference time: {:.3f} ms".format(det_time * 1000)
-            render_time_message = "OpenCV rendering time: {:.3f} ms".format(render_time * 1000)
-            if is_async_mode:
-                async_mode_message = "Async mode is on. Processing request {}".format(cur_request_id)
+    def __del__(self):
+        self.cap.release()
+        cv2.destroyAllWindows()
+
+    def frames(self):
+        cur_request_id = 0
+        next_request_id = 1
+
+        log.info("Starting inference in async mode...")
+        log.info("To switch between sync and async modes press Tab button")
+        log.info("To stop the demo execution press Esc button")
+
+        # Async doesn't work if True
+        # Request issues = Runtime Error: [REQUEST BUSY]
+        self.is_async_mode = False
+        #is_async_mode = True
+        render_time = 0
+        ret, frame = self.cap.read()
+
+        frameList = []
+
+        print("To close the application, press 'CTRL+C' or any key with focus on the output window")
+
+        while True:
+            if self.is_async_mode:
+                ret, next_frame = self.cap.read()
             else:
-                async_mode_message = "Async mode is off. Processing request {}".format(cur_request_id)
+                ret, frame = self.cap.read()
+            if not ret:
+                break
+            initial_w = self.cap.get(3)
+            initial_h = self.cap.get(4)
 
-            cv2.putText(frame, inf_time_message, (15, 15), cv2.FONT_HERSHEY_COMPLEX, 0.5, (200, 10, 10), 1)
-            cv2.putText(frame, render_time_message, (15, 30), cv2.FONT_HERSHEY_COMPLEX, 0.5, (10, 10, 200), 1)
-            cv2.putText(frame, async_mode_message, (10, int(initial_h - 20)), cv2.FONT_HERSHEY_COMPLEX, 0.5,
-                        (10, 10, 200), 1)
+            # Main sync point:
+            # in the truly Async mode we start the NEXT infer request, while waiting for the CURRENT to complete
+            # in the regular mode we start the CURRENT request and immediately wait for it's completion
+            inf_start = time.time()
+            if self.is_async_mode:
+                if ret:
+                    in_frame = cv2.resize(next_frame, (self.w, self.h))
+                    in_frame = in_frame.transpose((2, 0, 1))  # Change data layout from HWC to CHW
+                    in_frame = in_frame.reshape((self.n, self.c, self.h, self.w))
+                    self.exec_net.start_async(request_id=next_request_id, inputs={self.input_blob: in_frame})
+            else:
+                if ret:
+                    in_frame = cv2.resize(frame, (self.w, self.h))
+                    in_frame = in_frame.transpose((2, 0, 1))  # Change data layout from HWC to CHW
+                    in_frame = in_frame.reshape((self.n, self.c, self.h, self.w))
+                    self.exec_net.start_async(request_id=cur_request_id, inputs={self.input_blob: in_frame})
 
-        render_start = time.time()
+            if self.exec_net.requests[cur_request_id].wait(-1) == 0:
+                inf_end = time.time()
+                det_time = inf_end - inf_start
 
-        if not args.ns:
-            if ret:
-                cv2.imshow("Detection results", frame)
-            render_end = time.time()
-            render_time = render_end - render_start
+                # Parse detection results of the current request
+                res = self.exec_net.requests[cur_request_id].outputs[self.out_blob]
 
-        if is_async_mode:
-            cur_request_id, next_request_id = next_request_id, cur_request_id
+                for obj in res[0][0]:
+                    # Draw only objects when probability more than specified threshold
+                    if obj[2] > self.args.prob_threshold:
+                        xmin = int(obj[3] * initial_w)
+                        ymin = int(obj[4] * initial_h)
+                        xmax = int(obj[5] * initial_w)
+                        ymax = int(obj[6] * initial_h)
+                        class_id = int(obj[1])
+                        # Draw box and label\class_id
+                        color = (min(class_id * 12.5, 255), min(class_id * 7, 255), min(class_id * 5, 255))
+                        cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color, 2)
+                        det_label = self.labels_map[class_id] if self.labels_map else str(class_id)
+                        cv2.putText(frame, det_label + ' ' + str(round(obj[2] * 100, 1)) + ' %', (xmin, ymin - 7),
+                                    cv2.FONT_HERSHEY_COMPLEX, 0.6, color, 1)
+                        print('Object detected, class_id:', class_id, 'probability:', obj[2], 'xmin:', xmin, 'ymin:', ymin,
+                              'xmax:', xmax, 'ymax:', ymax)
 
-            frame = next_frame
-        key = cv2.waitKey(1)
-        if key == 27:
-            break
-        if 9 == key:
-            is_async_mode = not is_async_mode
-            log.info("Switched to {} mode".format("async" if is_async_mode else "sync"))
+                # Draw performance stats
+                inf_time_message = "Inference time: Not applicable for async mode" if self.is_async_mode else \
+                    "Inference time: {:.3f} ms".format(det_time * 1000)
+                render_time_message = "OpenCV rendering time: {:.3f} ms".format(render_time * 1000)
+                if self.is_async_mode:
+                    async_mode_message = "Async mode is on. Processing request {}".format(cur_request_id)
+                else:
+                    async_mode_message = "Async mode is off. Processing request {}".format(cur_request_id)
 
-    cap.release()
-    cv2.destroyAllWindows()
+                cv2.putText(frame, inf_time_message, (15, 15), cv2.FONT_HERSHEY_COMPLEX, 0.5, (200, 10, 10), 1)
+                cv2.putText(frame, render_time_message, (15, 30), cv2.FONT_HERSHEY_COMPLEX, 0.5, (10, 10, 200), 1)
+                cv2.putText(frame, async_mode_message, (10, int(initial_h - 20)), cv2.FONT_HERSHEY_COMPLEX, 0.5,
+                            (10, 10, 200), 1)
+
+            render_start = time.time()
+
+            yield cv2.imencode('.jpg', frame)[1].tobytes()
+
+            if not self.args.ns:
+                if ret:
+                    cv2.imshow("Detection results", frame)
+                render_end = time.time()
+                render_time = render_end - render_start
+
+            if self.is_async_mode:
+                cur_request_id, next_request_id = next_request_id, cur_request_id
+
+                frame = next_frame
+            key = cv2.waitKey(1)
+            if key == 27:
+                break
+            if 9 == key:
+                self.is_async_mode = not self.is_async_mode
+                log.info("Switched to {} mode".format("async" if self.is_async_mode else "sync"))
 
 
 if __name__ == '__main__':
-    sys.exit(main() or 0)
+    args = build_argparser().parse_args()
+    camera = Camera(args)
+    camera.frames()
+    del camera
