2016-08-02 1 views
-5

を昇順で最初のベクトルと仕分けベクトルをプッシュバック++ [0]×1のポイントである、その長さは常にcが、私は最初のベクトル ベクトルlをソートしようとしているため

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); 
    } 

} 

私はハウラインを使用してx1、x2、 Y1、Y2 あらゆるx1とソートこれはあなたの問題ですが...あなたはforループ内v1を定義することをわからない

+3

申し訳ありませんが、あなたがしたいことは非常に不明です。 – NathanOliver

+1

また、なぜ 'l'のような一文字の変数名を使用するのですか?それは '1'のように見えます。 – PaulMcKenzie

+2

'for(Iter = v1.begin(); Iter!= v1.end();){'無限ループ? uがために '意味した(イーター= v1.begin();!イーター= v1.end(); ++イーター){あなたはすべてのタイプミスを修正した後@VaibhavBajajに以下の答えとして' – DimChtz

答えて

4

の昇順を取得します。

for (size_t i = 0; i < lines.size(); 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; 
     } 
    // ... 
} 

だから、各反復、単一の値を印刷し、(単一の要素で)ベクトルを並べ替え、単一の要素を挿入し、ベクトルを作成し、にベクトルを破壊します。

提案:forループ外v1を定義します。

---編集---

aichaoによって指し示されるように、ソート、印刷部分は、おそらくループの外に優れています。

vector<int> v1; 

for (size_t i = 0; i < lines.size(); i++) 
{ 
    // ... 

     v1.push_back(l[0]); 

    // ... 
} 

sort(v1.begin(), v1.end()); 

for (vector<int>::const_iterator CIter = v1.cbegin(); CIter != v1.cend(); CIter++) { 
    cout << *CIter << endl; 
} 

のようなもの、あなたがC++ 11やC++ 14をコンパイルすることができた場合は、最後のforは単に

for (auto const & i : v1) 
    cout << i << endl; 

p.s:私の悪い英語のために後悔することができます。

+1

@ plzunderstandmyenglish彼の英語を理解してください。 –

+0

@FirstStep - max66 @ :-) – max66

+2

:あなたは 'v1'定義**と**のためのループ外' sort'とその後の出力を移動するように多分あなたはこれを編集だろうか? – aichao

関連する問題