error: OpenCV(4.8.0) /io/opencv/modules/core/src/copy.cpp:71: error: (-215:Assertion failed) cn <= 4 in function 'scalarToRawData'
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 5.4k
- Fork
- 1k
- Merge medio
- 22h 17m
- PR unite (30g)
- 3
Descrizione
here is my code that gives me an error.
def find_lane_pixels(binary_warped):
# Debug: Check the shape and type of binary_warped
print(f"binary_warped shape: {binary_warped.shape}, type: {binary_warped.dtype}")
histogram = np.sum(binary_warped[binary_warped.shape[0]//2:, 50:], axis=0)
out_img = np.dstack((binary_warped, binary_warped, binary_warped))
# Debug: Check the shape and type of out_img
print(f"out_img shape: {out_img.shape}, type: {out_img.dtype}")
midpoint = histogram.shape[0] // 2
leftx_base = np.argmax(histogram[:midpoint])
rightx_base = np.argmax(histogram[midpoint:]) + midpoint
nwindows = 9
margin = 100
minpix = 50
window_height = int(binary_warped.shape[0] // nwindows)
nonzero = binary_warped.nonzero()
nonzeroy = np.array(nonzero[0])
nonzerox = np.array(nonzero[1])
leftx_current = leftx_base
rightx_current = rightx_base
left_lane_inds = []
right_lane_inds = []
for window in range(nwindows):
win_y_low = binary_warped.shape[0] - (window+1) * window_height
win_y_high = binary_warped.shape[0] - window * window_height
win_xleft_low = leftx_current - margin
win_xleft_high = leftx_current + margin
win_xright_low = rightx_current - margin
win_xright_high = rightx_current + margin
# Ensure that window boundaries are within the image dimensions
win_xleft_low = max(0, win_xleft_low)
win_xleft_high = min(binary_warped.shape[1], win_xleft_high)
win_xright_low = max(0, win_xright_low)
win_xright_high = min(binary_warped.shape[1], win_xright_high)
cv2.rectangle(out_img, (win_xleft_low, win_y_low), (win_xleft_high, win_y_high), (0, 255, 0), 2)
cv2.rectangle(out_img, (win_xright_low, win_y_low), (win_xright_high, win_y_high), (0, 255, 0), 2)
good_left_inds = ((nonzeroy >= win_y_low) & (nonzeroy < win_y_high) &
(nonzerox >= win_xleft_low) & (nonzerox < win_xleft_high)).nonzero()[0]
good_right_inds = ((nonzeroy >= win_y_low) & (nonzeroy < win_y_high) &
(nonzerox >= win_xright_low) & (nonzerox < win_xright_high)).nonzero()[0]
left_lane_inds.append(good_left_inds)
right_lane_inds.append(good_right_inds)
if len(good_left_inds) > minpix:
leftx_current = int(np.mean(nonzerox[good_left_inds]))
if len(good_right_inds) > minpix:
rightx_current = int(np.mean(nonzerox[good_right_inds]))
try:
left_lane_inds = np.concatenate(left_lane_inds)
right_lane_inds = np.concatenate(right_lane_inds)
except ValueError:
print("An error occurred!")
pass
leftx = nonzerox[left_lane_inds]
lefty = nonzeroy[left_lane_inds]
rightx = nonzerox[right_lane_inds]
righty = nonzeroy[right_lane_inds]
return leftx, lefty, rightx, righty, out_img
def fit_polynomial_first_lane(binary_warped):
leftx, lefty, rightx, righty, out_img = find_lane_pixels(binary_warped)
left_fit = np.polyfit(lefty, leftx, 2)
right_fit = np.polyfit(righty, rightx, 2)
ploty = np.linspace(0, binary_warped.shape[0]-1, binary_warped.shape[0])
try:
left_fitx = left_fit[0] * ploty2 + left_fit[1] * ploty + left_fit[2]
right_fitx = right_fit[0] * ploty2 + right_fit[1] * ploty + right_fit[2]
except TypeError:
print('The function failed to fit a line!')
left_fitx = 1 * ploty2 + 1 * ploty
right_fitx = 1 * ploty2 + 1 * ploty
out_img[lefty, leftx] = [255, 0, 0]
out_img[righty, rightx] = [0, 0, 255]
left_pts = np.transpose(np.vstack((left_fitx, ploty))).astype(np.int32)
right_pts = np.transpose(np.vstack((right_fitx, ploty))).astype(np.int32)
cv2.polylines(out_img, np.int32([left_pts]), False, (255, 255, 0), thickness=5)
cv2.polylines(out_img, np.int32([right_pts]), False, (255, 255, 0), thickness=5)
return left_fit, right_fit, out_img
binary_warped pixel range: 0 to 255
binary_warped shape: (720, 1280, 3), type: uint8
out_img shape: (720, 1280, 9), type: uint8
error Traceback (most recent call last)
in <cell line: 129>()
146
147 # Find lane pixels and fit polynomial
--> 148 left_fit, right_fit, out_img = fit_polynomial_first_lane(binary_warped)
149
150 # Plot the results
1 frames
in find_lane_pixels(binary_warped)
66 win_xright_high = min(binary_warped.shape[1], win_xright_high)
67
---> 68 cv2.rectangle(out_img, (win_xleft_low, win_y_low), (win_xleft_high, win_y_high), (0, 255, 0), 2)
69 cv2.rectangle(out_img, (win_xright_low, win_y_low), (win_xright_high, win_y_high), (0, 255, 0), 2)
70
error: OpenCV(4.8.0) /io/opencv/modules/core/src/copy.cpp:71: error: (-215:Assertion failed) cn <= 4 in function 'scalarToRawData'
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in find_lane_pixels dalla costruzione di out_img e dalle chiamate a cv2.rectangle, usando le shapes stampate e l’assertion di OpenCV come indizi iniziali. Controlla le dimensioni dei canali previste dalle chiamate di disegno e traccia come binary_warped viene passato a fit_polynomial_first_lane. Il lavoro è completato quando il disegno delle finestre della corsia viene eseguito senza l’assertion e il successivo flusso di fitting polinomiale può essere raggiunto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- computer-vision
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100