【发布时间】:2017-06-09 15:41:32
【问题描述】:
我想使用轮廓进行对象检测。我可以将对象与背景分离。我在图像中心有一个边界框。我想当对象在边界框中时检测它。我使用`
for(int i = 0; i < contours.size(); i++) {
for (int j = 0; j < contours[i].size();j++) {
cout << contours[i][j] << endl;
// ...
用于显示 i 和 j 中的所有轮廓。并使用此代码
for(int x = 405; x < 455; x++) {
for (int y = 210; y < 280; y++) {
if (contours[i, j] == contours[x, y])
// ...
用于检测感兴趣区域中的对象。但是当我运行程序时,我的代码已中断if (contours[i, j] == contours[x, y])
.您有什么想法可以解决我的问题吗?谢谢您的帮助。
`//draw each contour with a random color
int idx = 0;
for (; idx >= 0; idx = hierarchy[idx][0]){ Scalar color(rand() & 255, rand() & 255);
if (contourArea(contours[idx]) < 20)
drawContours(dst2, contours, idx, color, CV_FILLED);}
for (int i = 0; i < contours.size(); i++){
for (int j = 0; j < contours[i].size();j++){
// cout << contours[i][j] << endl;
for (int x = 405; x < 455; x++) {
for (int y = 210; y < 280; y++){
if (contours[i][j] == contours[x][y]) {
rectangle(frame, rectangle2, Scalar(255, 255, 255)) }
}
}
}`
我有两个边界框,当对象位于比另一个边界框更小的边界框时,我想要隐藏。
【问题讨论】:
-
不应该是
contours[i][j] == contours[x][y]吗? -
我对此进行了测试,但结果没有任何变化
-
你能发布错误吗?
-
没有错误。我的程序构建成功但是当我运行它时,代码执行停止。
-
小心 C++ 的comma operator。
contours[i, j]几乎肯定不会像你认为的那样做。
标签: c++ opencv opencv-contour