-2
我使用Opencv在ptz相機上做出了認知編號。我的opencv不起作用
但是我的程序有很大的問題。
錯誤`./main.out「:雙重釋放或腐敗(!上一頁):
我認爲它正在泄漏內存。所以我試圖'清除()'來解除分配內存。但它不起作用。
如何解決?
#include "opencv2/opencv.hpp"
#include <iostream>
#include <unistd.h>
#include <time.h>
using namespace cv;
using namespace std;
Mat3b canvas;
string buttonText("Click me!");
Mat frame1;
Mat frame2;
Mat frame3;
Rect rect, temp_rect;
double ratio, delta_x, delta_y, gradient;
int count, friend_count = 0, refinery_count = 0;
void testfunc()
{
vector<Vec4i> hierarchy;
vector<vector<Point> > contours;
findContours(frame3, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point());
vector<vector<Point> > contours_poly(contours.size());
vector<Rect> boundRect(contours.size());
vector<Rect> boundRect2(contours.size());
for (int i = 0; i < contours.size(); i++) {
approxPolyDP(Mat(contours[i]), contours_poly[i], 1, true);
boundRect[i] = boundingRect(Mat(contours_poly[i]));
}
Mat drawing = Mat::zeros(frame3.size(), CV_8UC3);
for (int i = 0; i < contours.size(); i++)
{
ratio = (double)boundRect[i].height/boundRect[i].width;
if ((ratio <= 2.5) && (ratio >= 0.5) && (boundRect[i].area() <= 700) && (boundRect[i].area() >= 100))
{
drawContours(drawing, contours, i, Scalar(0, 255, 255), 1, 8, hierarchy, 0, Point());
rectangle(drawing, boundRect[i].tl(), boundRect[i].br(), Scalar(255, 0, 0), 1, 8, 0);
boundRect2[refinery_count] = boundRect[i];
refinery_count++;
}
}
boundRect2.resize(refinery_count);
imshow("camera4", drawing);
contours_poly.clear();
boundRect.clear();
boundRect2.clear();
contours.clear();
hierarchy.clear();
return;
}
int main(int argc, char** argv)
{
VideoCapture cap1(0);
if (!cap1.isOpened())
{
printf("ERROR. \n");
return -1;
}
// ************* This is notebook camera **********
// ************* This is PTZ camera **********
/*VideoCapture cap2;
string vStreamArs = "rtsp://root:[email protected]/ufirststream";
Mat video;
if (!cap2.open(vStreamArs))
{
cout << "[-] ERROR CODE 0 : Not connect camera!!" << endl;
return -1;
}
else
{
cout << "[+] Camera is connected!!" << endl;
}*/
// ************* This is PTZ camera **********
// ************* This is notebook camera **********
int select, plate_width;
while (1)
{
clock_t start = clock();
while (1)
{
if (!cap1.read(frame1))
{
cout << "[-] ERROR CODE 2 : No camera" << endl;
break;
}
imshow("output", frame1);
if ((clock() - start)/CLOCKS_PER_SEC > 10)
{
cout << "[+]Find" << endl;
break;
}
waitKey(1);
}
cvtColor(frame1, frame2, CV_BGR2GRAY);
Canny(frame2, frame3, 100, 300, 3);
imshow("camera3", frame3);
testfunc();
}
getchar();
return 0;
}
它不適用。 – modern