私は競争のために構築しているロボットのためにopenCVでいくつかの視覚処理を行う方法を書いています。フレームとプロセスオブジェクトはマットオブジェクトとインスタンスフィールドで、実際に動作することがわかっている別の方法でUSBカメラストリームから取得されます。別の方法でフレームオブジェクトを表示すると、プロセスメソッドを実行してもフレームは表示されませんが、そうでない場合は表示されません。フレームマットには、マーカと輪郭を描画する未加工画像が含まれ、プロセスマットは、マーカーと輪郭がフレームに描画される前に、処理された画像を格納するために使用されます。 [編集]:私はそれがcvtColorメソッドによって引き起こされていることがわかった。 (-215)(scn == 3 || scn == 4)& &(深さ== CV_8U ||深さ== CV_32F)の印刷エラーです。OpenCVのコンピュータビジョン処理コードが動作しない
//blurs the image to remove false positives
Imgproc.GaussianBlur(frame, processed, new Size(17, 17), 3);
//we are going to use HSV, not BGR for better filtration
Imgproc.cvtColor(processed, processed, Imgproc.COLOR_BGR2HSV);
//create scalars to hold high and low thresholds if using BGR
/*Scalar lowRange = new Scalar(RobotMap.lowBlueValue, RobotMap.lowGreenValue, RobotMap.lowRedValue);
Scalar highRange = new Scalar(RobotMap.highBlueValue, RobotMap.highGreenValue, RobotMap.highRedValue);*/
//create scalars if using HSV
Scalar lowRange = new Scalar(RobotMap.lowHue, RobotMap.lowSat, RobotMap.lowVal);
Scalar highRange = new Scalar(RobotMap.highHue, RobotMap.highSat, RobotMap.highVal);
//removes everything not in our filter range
Core.inRange(processed, lowRange, highRange, processed);
//mat used to for some of the contour finding
//TODO determine if necessary
Mat hierarchy = new Mat();
//create an arraylist to hold the unfiltered contours
ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
//find the contours in our image
findContours(processed, contours, hierarchy, RETR_LIST, CHAIN_APPROX_NONE);
//list of filtered contours
ArrayList<MatOfPoint> filteredContours = new ArrayList<MatOfPoint>();
//list of filtered contours as rect objects
ArrayList<Rect> rects = new ArrayList<Rect>();
//put our contours into rectangle objects if they pass our conditions
for (MatOfPoint contour : contours) {
//bounding rect objects are rectangles whose bounderies encompass all of the contour
Rect boundingRect = boundingRect(contour);
//check to see if we are a tallish rectangle with a largish area
if (boundingRect.height > boundingRect.width && boundingRect.area() > RobotMap.minimumArea) {
filteredContours.add(contour);
rects.add(boundingRect);
}
}
//draw our contours
drawContours(frame, filteredContours, -1, new Scalar(0, 0xFF, 0), FILLED);
//figure out how many targets there are
numTargets = filteredContours.size();
//draw marker at center of all rects
if(rects.size() > 0)
Imgproc.drawMarker(frame, center(rects), new Scalar(0xFF, 0, 0xFF));
//draw markers to show info on each rect
for (Rect rect : rects) {
Imgproc.drawMarker(frame, center(rect), new Scalar(0, 0, 0xFF));
Imgproc.drawMarker(frame, rect.br(), new Scalar(0xFF, 0, 0));
Imgproc.drawMarker(frame, rect.tl(), new Scalar(0xFF, 0, 0));
}
if(numTargets > 0)
center = center(rects).x;
ありがとうございました。私はエラーを見つけました。カスタムカメラサーバーの起動時に、フレームを取り込んでいたときに、フレームをまだ取り込めなかったことが判明しました。フレームが空の場合に返す最初のチェックを少し追加しました。これが私の最初の投稿なので、これを解決済みとするにはどうすればいいですか? – Nomaxx117