正方形を含む画像があり、その正方形に含まれる領域を抽出する必要があります。squares.cスクリプト(すべてのOpenCVディストリビューションのサンプルで利用可能)を適用した後、正方形のベクトルを取得し、それぞれの画像を保存する必要があります。
ユーザーkarlphillipはこれを提案しました:
for (size_t x = 0; x < squares.size(); x++)
{
Rect roi(squares[x][0].x, squares[x][0].y,
squares[x][1].x - squares[x][0].x,
squares[x][3].y - squares[x][0].y);
Mat subimage(image, roi);
}
元の画像で検出されたすべての正方形のサブ画像と呼ばれる新しいマットを生成するため
karlが私を思い出したように、画像で検出された点は完全な正方形を表していない可能性があります(上の画像でわかるように)が、私があなたに提案したコードはそれらがそうであると仮定しています。
実際、私はこのエラーを受け取ります:
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width &&
roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height &&
roi.y + roi.height <= m.rows) in Mat, file /usr/include/opencv/cxmat.hpp,
line 187
terminate called after throwing an instance of 'cv::Exception'
what(): /usr/include/opencv/cxmat.hpp:187: error: (-215) 0 <= roi.x &&
0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y &&
0 <= roi.height && roi.y + roi.height <= m.rows in function Mat
Aborted
スクリプトに非完全な正方形も受け入れさせるための提案はありますか?