Hello, I am trying to detect faces on a series of images in a node script and I am getting a segmentation fault.
This is the output of the console when the error occurs:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /tmp/opencv-20160626-26273-1a7s2xo/opencv-2.4.13/modules/core/src/array.cpp, line 2482
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /tmp/opencv-20160626-26273-1a7s2xo/opencv-2.4.13/modules/core/src/array.cpp, line 2482
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /tmp/opencv-20160626-26273-1a7s2xo/opencv-2.4.13/modules/core/src/array.cpp, line 2482
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /tmp/opencv-20160626-26273-1a7s2xo/opencv-2.4.13/modules/core/src/array.cpp, line 2482
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /tmp/opencv-20160626-26273-1a7s2xo/opencv-2.4.13/modules/core/src/array.cpp, line 2482
Segmentation fault: 11
This is the code that produces the error:
glob.sync('*.jpg' ).forEach( function( file,index,array ) {
cv.readImage(file, function(err, im){
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
if(faces.length>0){
//do something
}
else{
//do another thing
}
});
})
});
Closed for the following reason
question is off-topic or not relevant by
berak
close date 2016-08-08 20:58:14.952202
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
Description
Hello,
I am getting the below error, when i am running my code.
Please help me on this.
error:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/core/src/array.cpp, line 2482
Traceback (most recent call last):
File “/home/rajat/.config/gedit/tools/new-tool”, line 12, in
exec(sys.stdin.read())
File “”, line 85, in
File “”, line 60, in predict
cv2.error: /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat
code:
video_cap = cv2.VideoCapture(0) while True: ret, frame = video_cap.read() frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.05, 6) for face in faces: x, y, w, h = face face_region = gray[y:y+h, x:x+w] predicted_person_number, confidence = face_recognition.predict(face_region) cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 2) if predicted_person_number == 16: cv2.putText(frame, 'RB', (x,y), cv2.FONT_HERSHEY_TRIPLEX, 1, (255,255,255)) else: cv2.putText(frame, str(predicted_person_number), (x,y), cv2.FONT_HERSHEY_TRIPLEX, 1, (255,255,255)) cv2.imshow('Running face recognition...', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break video_cap.release() cv2.destroyAllWindows()
Code: Select all
#include <sstream>
#include <string>
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
using namespace cv;
//for blue color
int H_MINB = 98;
int H_MAXB = 100;
int S_MINB = 0;
int S_MAXB = 256;
int V_MINB = 0;
int V_MAXB = 256;
//for orange color
int H_MIN = 0;
int H_MAX = 256;
int S_MIN = 0;
int S_MAX = 200;
int V_MIN = 0;
int V_MAX = 256;
//default capture width and height
const int FRAME_WIDTH = 320;
const int FRAME_HEIGHT = 240;
//max number of objects to be detected in frame
const int MAX_NUM_OBJECTS=50;
//minimum and maximum object area
const int MIN_OBJECT_AREA = 25*25;
const int MAX_OBJECT_AREA = FRAME_HEIGHT*FRAME_WIDTH/2; ///640*480/2=153600
//names that will appear at the top of each window
const string windowName = "Original Image";
const string windowName1 = "HSV Image";
const string windowName2 = "Thresholded Image";
const string windowName3 = "After Morphological Operations";
const string windowName4 = "Thresholded Image blue";
const string trackbarWindowName = "Trackbars";
void on_trackbar( int, void* )
{//This function gets called whenever a
// trackbar position is changed
}
string intToString(int number){
std::stringstream ss;
ss << number;
return ss.str();
}
void createTrackbars(){
//create window for trackbars
namedWindow(trackbarWindowName,0);
//create memory to store trackbar name on window
char TrackbarName[50];
sprintf( TrackbarName, "H_MIN", H_MIN);
sprintf( TrackbarName, "H_MAX", H_MAX);
sprintf( TrackbarName, "S_MIN", S_MIN);
sprintf( TrackbarName, "S_MAX", S_MAX);
sprintf( TrackbarName, "V_MIN", V_MIN);
sprintf( TrackbarName, "V_MAX", V_MAX);
//create trackbars and insert them into window
// ----> ----> ---->
createTrackbar( "H_MIN", trackbarWindowName, &H_MIN, H_MAX, on_trackbar );
createTrackbar( "H_MAX", trackbarWindowName, &H_MAX, H_MAX, on_trackbar );
createTrackbar( "S_MIN", trackbarWindowName, &S_MIN, S_MAX, on_trackbar );
createTrackbar( "S_MAX", trackbarWindowName, &S_MAX, S_MAX, on_trackbar );
createTrackbar( "V_MIN", trackbarWindowName, &V_MIN, V_MAX, on_trackbar );
createTrackbar( "V_MAX", trackbarWindowName, &V_MAX, V_MAX, on_trackbar );
}
/////////////////////////////////////////////////////new//////////////////////////////////////////////////////////////////////
void drawObjectblue(int xblue, int yblue,Mat &frameblue){
circle(frameblue,Point(xblue,yblue),20,Scalar(0,255,0),2);
if(yblue-25>0)
line(frameblue,Point(xblue,yblue),Point(xblue,yblue-25),Scalar(0,255,0),2);
else line(frameblue,Point(xblue,yblue),Point(xblue,0),Scalar(0,255,0),2);
if(yblue+25<FRAME_HEIGHT)
line(frameblue,Point(xblue,yblue),Point(xblue,yblue+25),Scalar(0,255,0),2);
else line(frameblue,Point(xblue,yblue),Point(xblue,FRAME_HEIGHT),Scalar(0,255,0),2);
if(xblue-25>0)
line(frameblue,Point(xblue,yblue),Point(xblue-25,yblue),Scalar(0,255,0),2);
else line(frameblue,Point(xblue,yblue),Point(0,yblue),Scalar(0,255,0),2);
if(xblue+25<FRAME_WIDTH)
line(frameblue,Point(xblue,yblue),Point(xblue+25,yblue),Scalar(0,255,0),2);
else line(frameblue,Point(xblue,yblue),Point(FRAME_WIDTH,yblue),Scalar(0,255,0),2);
putText(frameblue,intToString(xblue)+","+intToString(yblue),Point(xblue,yblue+30),1,1,Scalar(0,255,0),2);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
void drawObject(int x, int y,Mat &frame){
circle(frame,Point(x,y),20,Scalar(0,255,0),2);
if(y-25>0)
line(frame,Point(x,y),Point(x,y-25),Scalar(0,255,0),2);
else line(frame,Point(x,y),Point(x,0),Scalar(0,255,0),2);
if(y+25<FRAME_HEIGHT)
line(frame,Point(x,y),Point(x,y+25),Scalar(0,255,0),2);
else line(frame,Point(x,y),Point(x,FRAME_HEIGHT),Scalar(0,255,0),2);
if(x-25>0)
line(frame,Point(x,y),Point(x-25,y),Scalar(0,255,0),2);
else line(frame,Point(x,y),Point(0,y),Scalar(0,255,0),2);
if(x+25<FRAME_WIDTH)
line(frame,Point(x,y),Point(x+25,y),Scalar(0,255,0),2);
else line(frame,Point(x,y),Point(FRAME_WIDTH,y),Scalar(0,255,0),2);
putText(frame,intToString(x)+","+intToString(y),Point(x,y+30),1,1,Scalar(0,255,0),2);
}
//////////////////////baru//////////////////
void morphOpsblue(Mat &threshblue){
Mat erodeElement = getStructuringElement( MORPH_RECT,Size(3,3));
Mat dilateElement = getStructuringElement( MORPH_RECT,Size(8,8));
erode(threshblue,threshblue,erodeElement);
erode(threshblue,threshblue,erodeElement);
dilate(threshblue,threshblue,dilateElement);
dilate(threshblue,threshblue,dilateElement);
}
///////////////////////baru////////////////////
void morphOps(Mat &thresh){
Mat erodeElement = getStructuringElement( MORPH_RECT,Size(3,3));
//dilate with larger element so make sure object is nicely visible
Mat dilateElement = getStructuringElement( MORPH_RECT,Size(8,8));
erode(thresh,thresh,erodeElement);
erode(thresh,thresh,erodeElement);
dilate(thresh,thresh,dilateElement);
dilate(thresh,thresh,dilateElement);
}
/////baru/////////////////////////////////////////////////////////////////////////////
void trackFilteredObjectblue(int &xblue, int &yblue, Mat thresholdblue, Mat &cameraFeed)
{
Mat tempblue;
thresholdblue.copyTo(tempblue);
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(tempblue,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );
double refArea = 0;
bool objectFound = false;
if (hierarchy.size() > 0) {
int numObjects = hierarchy.size();
if(numObjects<MAX_NUM_OBJECTS){
for (int index = 0; index >= 0; index = hierarchy[index][0]) {
Moments moment = moments((cv::Mat)contours[index]);
double area = moment.m00;
if(area>MIN_OBJECT_AREA && area<MAX_OBJECT_AREA && area>refArea){
xblue = moment.m10/area;
yblue = moment.m01/area;
objectFound = true;
refArea = area;
}else objectFound = false;
}
//let user know you found an object
if(objectFound ==true){
putText(cameraFeed,"Blue point track",Point(0,50),2,1,Scalar(0,255,0),2);
//draw object location on screen
drawObjectblue(xblue,yblue,cameraFeed);}
}else putText(cameraFeed,"TOO MUCH NOISE! ADJUST FILTER",Point(0,50),1,2,Scalar(0,0,255),2);
}
}
//////baru///////////////////////////////////////
void trackFilteredObject(int &x, int &y, Mat threshold, Mat &cameraFeed){
Mat temp;
threshold.copyTo(temp);
//these two vectors needed for output of findContours
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
//find contours of filtered image using openCV findContours function
findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );
//use moments method to find our filtered object
double refArea = 0;
bool objectFound = false;
if (hierarchy.size() > 0) {
int numObjects = hierarchy.size();
//if number of objects greater than MAX_NUM_OBJECTS we have a noisy filter
if(numObjects<MAX_NUM_OBJECTS){
for (int index = 0; index >= 0; index = hierarchy[index][0]) {
Moments moment = moments((cv::Mat)contours[index]);
double area = moment.m00;
if(area>MIN_OBJECT_AREA && area<MAX_OBJECT_AREA && area>refArea){
x = moment.m10/area;
y = moment.m01/area;
objectFound = true;
refArea = area;
}else objectFound = false;
}
//let user know you found an object
if(objectFound ==true){
putText(cameraFeed,"Tracking Object",Point(0,50),2,1,Scalar(0,255,0),2);
//draw object location on screen
drawObject(x,y,cameraFeed);}
}else putText(cameraFeed,"TOO MUCH NOISE! ADJUST FILTER",Point(0,50),1,2,Scalar(0,0,255),2);
}
}
int main(int argc, char* argv[])
{ char key=0;
bool trackObjects = true;
bool useMorphOps = true;
bool useMorphOpsblue = true;
Mat cameraFeed;
Mat HSV;
Mat thresholdblue;
Mat threshold;
int xblue=0, yblue=0;
int x=0, y=0;
VideoCapture capture;
//open capture object at location zero (default location for webcam)
capture.open(0);
//set height and width of capture frame
capture.set(CV_CAP_PROP_FRAME_WIDTH,FRAME_WIDTH);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,FRAME_HEIGHT);
while(key != 'Q' && key != 'q')
{ capture.read(cameraFeed);
cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
inRange(HSV,Scalar(H_MINB,S_MINB,V_MINB),Scalar(H_MAXB,S_MAXB,V_MAXB),thresholdblue);
inRange(HSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),threshold);
if(useMorphOpsblue)
morphOps(thresholdblue);
if(useMorphOps)
morphOps(threshold);
if(trackObjects)
(xblue,yblue,thresholdblue,cameraFeed);
(x,y,threshold,cameraFeed);
imshow(windowName2,threshold);
imshow(windowName4,thresholdblue);
imshow(windowName,cameraFeed); //originl pic
key = cvWaitKey(30);
}
return 0;
}
I can compile it, but it’ error after running it… what is the problem?
error:
Opencv Error: bad flag (parameter or structure field) (unrecognized or unsupperted array type) in cvGetMat, file build /opencv-XZa2gn/opencv-2.3.1/modules/core/src/array.cpp. line 2482
terminate called after throwing an instance of ‘cv::Exception’
what(): /build/opencv-XZa2gn/opencv-2.3.1/modules.core/src/array.cpp:2482 error: (-206) unrecognized or unsupported array type in function cvGetMat
Утечка памяти и вылет с ошибкой после запуска
20.09.2017, 20:30. Показов 1251. Ответов 4
Доброго времени суток.
Кажется я облажался и мне нужна помощь.
Код такой:
| C++ | ||
|
Код в принципе компилируется и работает, но жрет память. Я думаю, это связано с тем, что из памяти нигде не освобождается место от Mat grayMat; gray и frame.
На основе этого кода я написал еще один:
| C++ | ||
|
Код так же запускается, но тоже жрет память(
К тому же еще и вылетает с ошибкой в консоли через некоторое время после запуска (иногда может пару раз найти символ)
| C++ | ||
|
Никак не могу понять, что не так. Первый код от такой ошибки не страдает.
Добавлено через 3 часа 46 минут
С вылетом справился добавив промежуточную копию изображения в 57 строку.
Помогите разобраться с утечкой памяти!
0
