Ich programmiere ein maschinelles Lernskript, um Bilder aufzunehmen und zu beschriften. Ich habe mein Dataset in einem Ordner und ich füge sie in ein Array ein und erstelle ein weiteres Array für Labels. wenn ich versuche, svm.fit zu verwenden gibt es den Fehler:Laden von OpenCV Image To Scikit Learn
File "scikit.py", line 43, in <module>
clf.fit(arrayimg, arraylabel)
File "/home/mkmeral/.local/lib/python2.7/site-packages/sklearn/svm/base.py", line 151, in fit
X, y = check_X_y(X, y, dtype=np.float64, order='C', accept_sparse='csr')
File "/home/mkmeral/.local/lib/python2.7/site-packages/sklearn/utils/validation.py", line 521, in check_X_y
ensure_min_features, warn_on_dtype, estimator)
File "/home/mkmeral/.local/lib/python2.7/site-packages/sklearn/utils/validation.py", line 405, in check_array
% (array.ndim, estimator_name))
ValueError: Found array with dim 3. Estimator expected <= 2.
Und hier ist das Skript schrieb ich:
import cv2
import numpy as py
from sklearn import svm
camera_port = 0
camera = cv2.VideoCapture(camera_port)
ramp_frames = 5
def getImage():
retval, im = camera.read()
gray_image = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
return gray_image
def insertToArray(arrayone, arraytwo, no, true):
if (true==1):
directory = "/home/mkmeral/Desktop/opencv/strue/"
arraytwo.append(1)
else:
directory = "/home/mkmeral/Desktop/opencv/sfalse/"
arraytwo.append(0)
im = cv2.imread(directory + str(no) + ".png")
gray_image = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
arrayone.append(gray_image)
arrayimg = []
arraylabel = []
count = 1
while (count<43):
insertToArray(arrayimg, arraylabel, count, 1)
print("True = " , count)
count = count + 1
count = 0
while (count<43):
insertToArray(arrayimg, arraylabel, count, 0)
print("False = ", count)
count = count + 1
print("Done adding to arrays")
clf = svm.SVC()
print("Done adding to arrayssss")
clf.fit(arrayimg, arraylabel)
print("Done fitting")
for i in xrange(ramp_frames):
temp = getImage()
testimage = getImage()
clf.predict(testimage)
Wie kann ich diese Bilder passen lernen Scikit und würde es ein Problem machen das von der Webcam aufgenommene Bild vorhersagen?