C++记忆霍夫莱恩斯·
C++ Memory HoughLinesP
我用HoughLinesP做了一个程序,现在它只是在第17帧时卡住了,它正在运行一些东西但没有结果。使用另一个视频,它会卡在第 13 帧(即对象进入视频的那一刻)。我认为这是一个内存问题,但是我已经清理了我在论坛上发现的所有矢量。我也发现了类似的东西,解决方案是:
将您的应用程序链接到与 OpenCV 库版本相同的 CRT
我不明白该怎么做,我正在使用MSVC 2013,更新4。有我的代码:
struct myclass {
bool operator() (Vec4i l1, Vec4i l2) { return (l1[0] < l2[0]); }
} myobjectv;
struct myclass1 {
bool operator() (Vec4i l1, Vec4i l2) { return (l1[1] < l2[1]); }
} myobjecth;
int main(int argc, char** argv)
{
vector<Rect*> components(250, (Rect *)NULL);
VideoCapture video1;
int vektor, ukupno_komponenti;
int width, height, frames1, fps1;
video1.open(argv[1]);
fps1 = video1.get(CV_CAP_PROP_FPS);
width = video1.get(CAP_PROP_FRAME_WIDTH);
height = video1.get(CAP_PROP_FRAME_HEIGHT);
frames1 = video1.get(CAP_PROP_FRAME_COUNT);
int i = 0;
int j = 0;
Mat src, dst, cdst, krug;
Mat frameTime1(height, width, CV_8UC3, Scalar(0, 0, 0));
int fvd = 0;
while (1)
{
fvd++;
cout << fvd;
video1 >> src;
bool bSuccess = video1.read(src);
if (!bSuccess) //if not success, break loop
{
cout << "ERROR: Cannot read a frame from video file" << endl;
break;
}
Mat roi_w1;
roi_w1 = src(Rect(150, 50, 320, 320));
GaussianBlur(roi_w1, roi_w1, Size(11, 11), 0);
Canny(roi_w1, dst, 50, 200, 3);
cvtColor(dst, cdst, CV_GRAY2BGR);
vector<Vec4i> lines;
vector<Vec4i> h_lines;
vector<Vec4i> v_lines;
HoughLinesP(dst, lines, 1, CV_PI / 220, 50, 150, 30);
for (size_t i = 0; i < lines.size(); i++)
{
Vec4i l = lines[i];
double Angle = atan2(l[3] - l[1], l[2] - l[0]) * 180.0 / CV_PI;
if (Angle < 0) Angle = Angle + 360;
//vertikalne
if ((abs(Angle) > 88) | (abs(Angle) == 90)){
v_lines.push_back(lines[i]);
}
//horizontalne
if ((abs(Angle) == 0) | (abs(Angle) < 2)){
h_lines.push_back(lines[i]);
}
}
int broj[10] = { 0 };
sort(v_lines.begin(), v_lines.end(), myobjectv);
vector<Vec4i> vv_lines;
for (size_t i = 0; i < v_lines.size() - 1; i++)
{
for (size_t j = i + 1; j < v_lines.size(); j++)
{
Vec4i l1 = v_lines[i];
Vec4i l2 = v_lines[j];
if ((abs(l1[2] - l2[2]) < 20)){
if ((broj[i] == 0) && (broj[j] == 0))
{
vv_lines.push_back(l1);
broj[i]++;
broj[j]++;
}
}
else{
if ((broj[i] == 0)){ vv_lines.push_back(l1); }
if ((broj[j] == 0)){ vv_lines.push_back(l2); }
}
}
}
for (size_t i = 0; i < vv_lines.size(); i++)
{
Vec4i lcr = vv_lines[i];
line(cdst, Point(lcr[0], lcr[1]), Point(lcr[2], lcr[3]), Scalar(0, 255, 0), 3, CV_AA);
}
int brojb[10] = { 0 };
sort(h_lines.begin(), h_lines.end(), myobjecth);
vector<Vec4i> hh_lines;
for (size_t i = 0; i < h_lines.size(); i++)
{
for (size_t j = i; j < h_lines.size() - 1; j++)
{
Vec4i l1 = h_lines[i];
Vec4i l2 = h_lines[j];
if ((abs(l1[1] - l2[1]) < 20)){
if ((brojb[i] == 0) && (brojb[j] == 0))
{
hh_lines.push_back(l1);
brojb[i]++;
brojb[j]++;
}
}
else{
if ((brojb[i] == 0)){ hh_lines.push_back(l1); }
if ((brojb[j] == 0)){ hh_lines.push_back(l2); }
}
}
}
for (size_t i = 0; i < hh_lines.size(); i++)
{
Vec4i lcr = hh_lines[i];
line(cdst, Point(lcr[0], lcr[1]), Point(lcr[2], lcr[3]), Scalar(0, 255, 0), 3, CV_AA);
}
vector<Point> grid;
Point P;
int s = 0;
for (size_t i = 0; i < hh_lines.size(); i++)
{
for (size_t j = 0; j < vv_lines.size(); j++)
{
Vec4i lb1 = hh_lines[i];
Vec4i lb2 = vv_lines[j];
float p1startx = lb1[0];
float p1starty = lb1[1];
float p1endx = lb1[2];
float p1endy = lb1[3];
float p2startx = lb2[0];
float p2starty = lb2[1];
float p2endx = lb2[2];
float p2endy = lb2[3];
if ((p2startx>p1startx)&(p2startx < p1endx)){
P.x = p2startx;
P.y = p1starty;
grid.push_back(P);
circle(cdst, P, 3, Scalar(0, 0, 255), -1, 8, 0);
s++;
}
}
}
vector<Vec4i>().swap(lines);
vector<Vec4i>().swap(h_lines);
vector<Vec4i>().swap(hh_lines);
vector<Vec4i>().swap(v_lines);
vector<Vec4i>().swap(vv_lines);
}
return 0;
}
问题可能在这里:
if ((abs(Angle) > 88) | (abs(Angle) == 90))
{
v_lines.push_back(lines[i]);
}
//horizontalne
if ((abs(Angle) == 0) | (abs(Angle) < 2))
{
h_lines.push_back(lines[i]);
}
您需要使用逻辑 OR ( ||
) 运算符,而不是错误使用的按位 OR ( |
)。
if ((abs(Angle) > 88) || (abs(Angle) == 90))
{
...
}
if ((abs(Angle) == 0) || (abs(Angle) < 2))
{
...
}
相关文章:
- 松弛原子与无同步情况下的记忆连贯性
- 递归函数有效,但无法记忆
- 如何将记忆应用于此递归函数?
- 共享记忆:让我们谈谈它的特殊性
- 为什么nlohmann不释放记忆
- CPP 中的瓦尔格林德和记忆泄漏:"Conditional jump or move depends on uninitialised values"
- C++17 多态记忆资源不起作用
- 我是否漏了记忆?
- 关于记忆后这种递归关系的时间复杂度
- 记忆栅栏和记忆屏障是一样的吗
- 使用记忆在 C++ 中实现 Knapstack
- 无论如何可以将webm / mp4文件编译/记忆为.exe程序吗?(C++)
- 如何在硬币兑换中添加记忆
- 动态记忆的删除是如何真正起作用的
- C++遗传,记忆问题
- 使用未声明的标识符"nothrow";你是说"扔"吗?记忆
- Qt驱动器下拉列表仅列出USB记忆棒
- 我找不到瓦尔格林德告诉我的记忆链接
- DFS + 记忆解决方案在 LeetCode 上获取 TLE
- 根据呼叫位置进行记忆