【发布时间】:2016-08-02 17:45:14
【问题描述】:
我正在尝试对第一个向量进行排序 向量 l[0] 是 x1 的点,那么它的长度总是变化的
vector<int> v1;
v1.push_back(l[0]);
vector<int>::iterator Iter = v1.begin();
for (Iter = v1.begin(); Iter != v1.end(); Iter++){
sort(v1.begin(), v1.end());
cout << *Iter << endl;
它没有任何错误,但不能按顺序排序。我该如何解决?
编辑---------------------------------------------- ------------------------------
void thresh_callback(int, void*)
{
/// Load source image and convert it to gray
src = imread(img_file, 1);
Mat threshold_output;
Mat threshold_output1;
Mat dst;
vector<vector<Point> > contours;
/// Detect edges using Threshold
Canny(src_hist, threshold_output, thresh, thresh * 3, 3, false);
Sharpen(threshold_output, threshold_output1);
cvtColor(threshold_output1, dst, CV_GRAY2BGR);
vector<Vec4i> lines;
HoughLinesP(threshold_output1, lines, 1, CV_PI / 180, thresh1, min_line, max_gap);
int erosion_size = 1;
Mat element = getStructuringElement(MORPH_ERODE,
Size(2 * erosion_size + 1, 2 * erosion_size + 1),
Point(erosion_size, erosion_size));
/// Apply the erosion operation
dilate(dst, dst, element);
imshow("Source", dst);
for (size_t i = 0; i < lines.size(); i++)
{
Vec4i l = lines[i];
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
int dx = l[2] - l[0];
int dy = l[3] - l[1];
double rad = atan2(dx, dy);
double degree = (rad * 180) / M_PI;
if (degree >= 180) degree -= 180;
if (degree < 15 || degree > 165) {
line(src, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 0, 255), 1, 8);
//printf("%lf\n", degree);
//printf("%d, %d, %d, %d, %d\n", l[0], l[1], l[2], l[3], i);
vector<int> v1;
v1.push_back(l[0]);
vector<int>::iterator Iter = v1.begin();
sort(v1.begin(), v1.end());
for (Iter = v1.begin(); Iter != v1.end(); Iter++){
cout << *Iter << endl;
}
}
imshow("source", src);
}
}
我使用 houghline 并找出 x1,x2,y1,y2 的点 并获取每个 x1 并按升序排序
【问题讨论】:
-
很抱歉,您想做什么还不清楚。
-
另外,为什么要使用像
l这样的单字母变量名?它看起来像1。 -
for (Iter = v1.begin(); Iter != v1.end();){无限循环?你是说for (Iter = v1.begin(); Iter != v1.end(); ++Iter){ -
照原样,在您修复所有拼写错误以便它像下面的@VaibhavBajaj 答案那样实际编译后,您将排序一个
int,因为这就是您的所有push_back到v1。你真正想要排序的是什么? -
我们能有最小的编译程序来显示您遇到的问题吗?您问题中的代码示例缺少可能对发现问题很重要的周边信息。