【发布时间】:2015-09-16 03:18:37
【问题描述】:
我正在尝试将图像的一个区域移动到中心,我成功地获得了它的轮廓,并且我知道如何将它放在中心。
但我想要的是移动位于中心的轮廓(黄色和黑色)内的像素,而不仅仅是轮廓(CV_FILLED 是粉红色的)。
图片:
代码:
//Then segment the image. save in Mat crop
// ---- Center image -----
// pos : contour interest
RotatedRect rr = fitEllipse(contours[pos]);
vector<Point>&contour = contours[pos];
//http://stackoverflow.com/a/29467236/4595387
//difference between the centre of the image and centre of the contour
Point center = Point( crop.cols/2, crop.rows/2 );
int nX = center.x - rr.center.x;
int nY = center.y - rr.center.y;
for (size_t i=0; i< contour.size(); i++)
{
contour[i].x += nX;
contour[i].y += nY;
}
cout << "x: " << rr.center.x;
cout << "y: " << rr.center.y;
//color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
//contour of the image to the center.
cv::drawContours(crop, contours, pos, color, CV_FILLED);
imshow("In",imagen_src);
imshow("Out",crop);
【问题讨论】:
-
贴出你到目前为止尝试过的代码,然后插入正确的方法来做到这一点会更容易。
-
完成。谢谢你的建议。
-
发布了将黄色项目移动到图像中心的答案。让我知道它是否适合您。