【发布时间】:2017-02-17 12:13:30
【问题描述】:
我正在尝试计算下面骨架化图像中的端点数。我在这里使用向量。我需要的是打印向量,而不仅仅是计数。我尝试了很多方法。但是没有用。我是打开简历的新手,我从互联网上找到了以下代码。谁能帮我打印出这段代码实际得到的向量。代码如下。
// get the end points
// Declare variable to count neighbourhood pixels
int count, numberOFEndpoints;
// To store a pixel intensity
uchar pix;
numberOFEndpoints = 0;
// To store the ending co-ordinates
std::vector<int> coords;
// For each pixel in our image...
for (int i = 1; i < CopyofSkeletionize.rows - 1; i++) {
for (int j = 1; j < CopyofSkeletionize.cols - 1; j++) {
// See what the pixel is at this location
pix = CopyofSkeletionize.at<uchar>(i, j);
// If not a skeleton point, skip
if (pix == 0)
continue;
// Reset counter
count = 0;
// For each pixel in the neighbourhood
// centered at this skeleton location...
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
// Get the pixel in the neighbourhood
pix = CopyofSkeletionize.at<uchar>(i + y, j + x);
// Count if non-zero
if (pix != 0)
count++;
}
}
// If count is exactly 2, add co-ordinates to vector
if (count == 2) {
coords.push_back(i);
coords.push_back(j);
numberOFEndpoints = numberOFEndpoints + 1;
}
}
}
printf("numberOFEndpoints : %d \n", numberOFEndpoints);
我在互联网上使用了这段代码,但它不起作用。 for (int i = 0; i
【问题讨论】: