일부 개체를 감지하려는 비디오를 처리 중입니다.원치 않는 윤곽 필터링 - C++을 사용한 opencv
먼저 배경을 제거한 다음 회색으로 만들어 cv::threshold
과 그 이후에 cv::findcontours
을 사용하여 이진 이미지를 만듭니다.
너무 길거나 너무 짧은 윤곽을 제거하고 싶습니다. "Opencv 2 cookbook"에서 이런 이유로 코드를 발견했습니다. 하지만 내 비디오의 21 번째 프레임에 런타임 오류가 있습니다.
// Eliminate too short or too long contours
size_t cmin{ 15 }; // minimum contour length
size_t cmax{ 120 }; // maximum contour length
std::vector<std::vector<cv::Point> >::
const_iterator itc = contours.begin();
while (itc != contours.end()) {
if (itc->size() < cmin || itc->size() > cmax)
itc = contours.erase(itc);
else
++itc;
}
나는 검색 및 다른 코드를 발견하고는 동일한 프레임에 동일한 오류가 있습니다
double min_area = 500; // area threshold
double max_area = 1500; // area threshold
for (int i = 0; i < contours.size(); i++) // iterate through each contour.
{
double area = contourArea(contours[i], false); // Find the area of contour
if (area < min_area || area > max_area)
contours.erase(contours.begin() + i);
}
을하고 나는 새로운 벡터를 만들어 단지에 허용 윤곽을 복사하는 코드를 썼다. 뿐만 아니라 동일한 프레임에 같은 오류가 있습니다 : 나는 다른 동영상을 시도
std::vector<std::vector<cv::Point> > goodcontours;
size_t cmin{ 15 };
size_t cmax{ 120 };
double contourlength = 1;
size_t contoursize = contours.size();
for (int i = 0; i != contoursize;i++) {
contourlength = cv::arcLength(contours[i], true);
if (contourlength > cmin && contourlength < cmax)
goodcontours.push_back(contours.at(i));
}
을 그들 모두는 특정 프레임에서 동일한 문제가 있습니다.
오류가 발생하기 전에 불필요한 윤곽선을 볼 수 있으며 실제로 제거되지 않았 음을 의미합니다.
오류는 단지 말 : 0x75017FB2 (ucrtbase.dll)에서
처리되지 않은 예외
당신이 윤곽을 여과하기위한 어떤 제안이 있습니까? 내 친구의
one of my video frames contours
내가 ** 추측하고 **는 윤곽이'contourArea 일치하지 않는과 관련이 있음을 '가정 (아마도 너무 작습니까?). 좀 더 상세한 정보 메시지가 있어야합니다. – slawekwin