Ask Your Question

RGB error python

asked 2018-09-13 06:46:12 -0600

Aleander gravatar image

updated 2018-09-13 07:37:20 -0600

error generated after a runtime

Traceback (most recent call last): File "C:/detectordeobjetos/", line 31, in <module> objetosDetectados = detector(frame) RuntimeError: Unsupported image type, must be 8bit gray or RGB image. [h264 @ 000000cedf0fe920] negative number of zero coeffs at 78 6 [h264 @ 000000cedf0fe920] error while decoding MB 78 6


import dlib
import cv2
import sys
import time
import requests

ip = "rtsp://admin:[email protected]/doc/page/preview.asp"
detector = dlib.simple_object_detector('C:/detectordeobjetos/thor.svm')
ipp = ("")
Nome = 'Detector de Objetos'
fonte = cv2.FONT_ITALIC
captura = cv2.VideoCapture(ip)
x = 0
tempo = 0
sinal = 0

> while captura.isOpened():

    from datetime import datetime

    data_e_hora_atuais =
    data_e_hora_em_texto = data_e_hora_atuais.strftime('%d/%m/%Y %H:%M')
    conectado, frame =
    tempo += 1


    sinal += 1
    objetosDetectados = detector(frame)
    for o in objetosDetectados:
        e, t, d, f = (int(o.left()), int(, int(o.right()), int(o.bottom()))
        cv2.rectangle(frame, (e, t), (d, f), (0, 255, 0), 1)
        cv2.putText(frame, 'Eixo Detectado', (e, t), fonte, 1.0, (0, 255, 0), 2, cv2.LINE_4)
        print("Objeto foi detectado")
        tempo = 0
        sinal = 0

    if sinal == 5:
        xml = ("""<?xml version="1.0" encoding="iso-8859-1"?>
                    <dthora>""" + str(data_e_hora_em_texto) + """</dthora> </call> </calls>""")
        url = ''
        r =, {'data': xml}).text
        print("---Enviando Sinal ---")
        sinal = 0

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-09-13 08:10:50 -0600

holger gravatar image

Well your problem is in the error message "Unsupported image type, must be 8bit gray or RGB image. " So either supply a grayscale or RGB image. Opencv reads image as BGR per default. Its easy to convert between them with cv2.cvtColor()

P.S I really like spanish(Hola amigo) but try not to mix english variables names with spanish - its hard to understand imho.

edit flag offensive delete link more


I converted it to gray but lost a lot of efficiency in detecting objects would have some other way

Aleander gravatar imageAleander ( 2018-09-13 08:41:06 -0600 )edit

and now gives the following error

[rtsp @ 000000b48fd685a0] RTP: PT=60: bad cseq ba45 expected=a875
[h264 @ 000000b4943f9ae0] P sub_mb_type 6 out of range at 79 37
[h264 @ 000000b4943f9ae0] error while decoding MB 79 37
[h264 @ 000000b493cce2e0] negative number of zero coeffs at 52 8
[h264 @ 000000b493cce2e0] error while decoding MB 52 8
Aleander gravatar imageAleander ( 2018-09-13 08:41:34 -0600 )edit

Hmm you would need to read about the input data for your dlib model - what is the expected input dimension?

Try to use COLOR_BGR2RGB. Try to check what the input dimension is and probably resize before feeding it to detector.

If this is not working - you would need to read more about the object detector you want to use.

holger gravatar imageholger ( 2018-09-13 08:50:57 -0600 )edit

I managed to trangormando it in the color but now it does not detect from far

Aleander gravatar imageAleander ( 2018-09-13 09:39:26 -0600 )edit

Different problem, maybe different question. The problem is within your dlib detector then and most likely has nothing to do with open cv anymore.

Again - please read and follow:

  • Check what the input size in pixels your dlib model wants
  • Use open cv to resize to that dimension (please keep aspect ratio!)
  • Feed it to the network

Thats it for now from my side - Good Luck!

holger gravatar imageholger ( 2018-09-13 11:09:35 -0600 )edit

Question Tools

1 follower


Asked: 2018-09-13 06:46:12 -0600

Seen: 2,991 times

Last updated: Sep 13 '18