Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n') TypeError: can't concat NoneType to bytes #10

Open
ozicmoi opened this issue Jun 6, 2022 · 0 comments

Comments

@ozicmoi
Copy link

ozicmoi commented Jun 6, 2022

Hello there. I want to run the Yolov5 object detection model through flask. I am getting this error. My codes are as follows. Can you help me please?

``import cv2
import numpy as np
import cv2
import time
import torch
import pytesseract

model = torch.hub.load('ultralytics/yolov5', 'custom', path='/home/uni/Masaüstü/yolov5/plaka.pt') # plate detection

class VideoCamera(object):
def init(self):
self.video = cv2.VideoCapture("rtsp://admin:@192.168.1.24:554/mode=real&idc=1&ids=2")

def __del__(self):
    self.video.release()

def get_frame(self):
    success, image = self.video.read()
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    prev_frame_time = 0
    new_frame_time = 0
    image = cv2.resize(image, (500, 300))
    results = model(image)
    for _, det in enumerate(results.xyxy[0]):  # convert from tensor to numpy
        box = det.detach().cpu().numpy()[:5]  # convert from float to integer
        box = [int(x) for x in box]
        x1, y1, x2, y2, name = box  # crop the license plate image part
        image = image[y1:y2, x1:x2].copy()
        label = "plate"
        color = (0, 255, 255)
        cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 255), 2)  # draw a box on original image
        font = cv2.FONT_HERSHEY_SIMPLEX
        new_frame_time = time.time()
        fps = 1 / (new_frame_time - prev_frame_time)
        prev_frame_time = new_frame_time
        fps = int(fps)
        fps = str(fps)
        image=cv2.putText(image, fps, (7, 70), font, 3, (100, 255, 0), 3, cv2.LINE_AA)


        ret, jpeg = cv2.imencode('.jpg', image)
        return jpeg.tobytes()

``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant