2017-07-09 3 views
1

Ich habe vor kurzem begonnen, OpenCV zu erkunden, und ich bin sehr dafür bekannt. Ich habe Probleme beim Anzeigen eines skalierten Videoframes in einem Originalvideoframe. Hoffe, das macht Sinn. Alles funktioniert gut, aber wenn ich versuchte, die Farbe des skalierten Videos zu ändern, erhalte ich einen Fehler. Hier ist mein Code hoffentlich selbsterklärend.Opencv-Python Eingabe-Array-Fehler

import CV2 import numpy als np

cap = cv2.VideoCapture (0)

während True: # "ret" liefert einen Rahmen ret, frame = cap.read()

#Draw a rectangle at given location 
cv2.rectangle(frame,(500,80),(800,380),(0,255,0),5) 

#takes a sample of the frame marked by the rectangle area(y,x) 
face_track = frame[80:380, 500:800] 
#converts the sample to gray 
grayscaled = cv2.cvtColor(face_track,cv2.COLOR_BGR2GRAY) 
#threshold range of sample 
retvl, threshold = cv2.threshold(grayscaled,125,125,cv2.THRESH_BINARY) 

#overwrites/display a new area with the sample taken by face_track in the left top corner of the frame 
frame[0:300, 0:300] = threshold 

#displays the frames captured by cap 
cv2.imshow('frame',frame) 
#cv2.imshow('frame',threshold) 

#if key stroke is 'q' break and terminate 
if cv2.waitKey(0) & 0xff == ord('q'): 
    break 

cap.release() cv2.destroyAllWindows()

folgende Der Fehler ist: Rahmen [0: 300, 0: 300] = Schwelle Valueerror: konnte nicht Eingabearray Broadcast von Form (300,300) in Form (300,300,3)

Wenn ich es auf diese Änderung: Rahmen [0: 300, 0: 300] = Face_track es funktioniert. Aber ist nicht was ich will.

Auch wenn ich Schwellwert stattdessen als v2.imshow ('Rahmen', Schwelle), ausgeben würde es auch funktionieren. Aber wieder nicht was ich will.

Gibt es außer cv2.cvtColor eine andere Funktion, die die Array-Form nicht ändert?

Antwort

0

convert dreschen grau BGR

cv2.cvtColor (Schwelle, cv2.COLOR_GRAY2BGR)

+0

Nizza, es funktionierte! Vielen Dank. Würde es dir etwas ausmachen zu erklären, was passiert ist? @bluekid –

+0

Farbbild hat 3 Kanal, Graustufen 1 –