使用findContours
(OpenCV)时如何避免检测图像的帧?直到我发现OpenCV findContours始终为每个对象找到两个轮廓并实现该答案之前,我一直没有始终如一地检测内部对象(对象线被分成几部分),但是现在我每次都检测到图像帧。
该图像是从底部看到的四旋翼无人机的图像;我正在使用一系列图片来“训练”物体检测。为此,我需要确保我能够始终如一地获得UAV对象。我想我可以反转颜色,但这似乎是一个肮脏的技巧。
这些图像首先是紧接在其之前的输入图像findContours
,以及由此产生的轮廓。我有七个测试图像,所有七个都有一个框架和一个无人机。的时刻非常相似(如预期)。
查找轮廓/对象并计算hu力矩的代码(C ++ 11,相当混乱):
#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <fstream>
#include <string>
using namespace cv;
using namespace std;
#define EROSION_SIZE 1
#define ERODE_CANNY_PREP_ITERATIONS 5
int main() {
Mat image, canny_output, element, padded;
RNG rng(12345);
int numbers[] = {195, 223, 260, 295, 331, 368, 396};
string pre = "/home/alrekr/Pictures/UAS/hu-images/frame_";
string middle = "_threshold";
string post = ".png";
string filename = "";
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
ofstream fout("/home/alrekr/Pictures/UAS/hu-data/hu.dat");
element …
Run Code Online (Sandbox Code Playgroud)