int* poly = new int[lines.size()];  
  for(int i=0;i<lines.size();i++)poly[i] = - 1;  
  int curPoly = 0;  
       vector<vector<cv::Point2f> > corners;  
      for (int i = 0; i < lines.size(); i++)  
      {  
           for (int j = i+1; j < lines.size(); j++)  
           {  

                cv::Point2f pt = computeIntersect(lines[i], lines[j]);  
                if (pt.x >= 0 && pt.y >= 0&&pt.x<img2.size().width&&pt.y<img2.size().height){  

                     if(poly[i]==-1&&poly[j] == -1){  
                          vector<Point2f> v;  
                          v.push_back(pt);  
                          corners.push_back(v);       
                          poly[i] = curPoly;  
                          poly[j] = curPoly;  
                          curPoly++;  
                          continue;  
                     }  
                     if(poly[i]==-1&&poly[j]>=0){  
                          corners[poly[j]].push_back(pt);  
                          poly[i] = poly[j];  
                          continue;  
                     }  
                     if(poly[i]>=0&&poly[j]==-1){  
                          corners[poly[i]].push_back(pt);  
                          poly[j] = poly[i];  
                          continue;  
                     }  
                     if(poly[i]>=0&&poly[j]>=0){  
                          if(poly[i]==poly[j]){  
                               corners[poly[i]].push_back(pt);  
                               continue;  
                          }  

                          for(int k=0;k<corners[poly[j]].size();k++){  
                               corners[poly[i]].push_back(corners[poly[j]][k]);  
                          }  

                          corners[poly[j]].clear();  
                          poly[j] = poly[i];  
                          continue;  
                     }  
                }  
           }  
      }  

Recommended Answers

All 6 Replies

That's not python. I dumped it into http://pythonfiddle.com/pysomething and it looks like you have a lot of work ahead.

You didn't post much detail. Just a post title and code. Don't be shy. If you want members to write your code, just ask. But read this first.
https://www.daniweb.com/programming/web-development/threads/435023/read-this-before-posting-a-question

While I port code I have two methods I've used over the years. One is to line by line, the other is consider what it did and then code anew to give the same result or what I feel I need it to do.

sorry for my bad question and i 'am verry bad in c++ please help me to understan the c++ code

i try to convert the code and this is the result but i think it is not efecient

h,w,_ = img2.shape
print h,w
poly = np.zeros((plines.size,1,1))

for i in range(plines.size):
    poly[i] = -1
curPoly = 0

corners = []
cor = []
corx = []
cory = []
for i in range(0,a):
    k = i+1
    for j in range(k,a):
        x,y = intersection(plines[i], plines[j])
        m = x,y
        if (x >= 0 and y >= 0 and x<w and y<h):
            corners.append(m) 
            corx.append(x)
            cory.append(y)
            #corners = np.append(corners,m)
            if(poly[i]==-1 and poly[j] == -1):
                v = np.array([])
                v = np.append(v,m)
                corners.append(v)
                print corners
                poly[i] = curPoly
                poly[j] = curPoly
                curPoly += 1
                continue
            if(poly[i]==-1 and poly[j]>=0):
                print poly[j]
                corners.append(corners[int(poly[j][0][0])])
                poly[i] = poly[j]
                continue
            if(poly[i]>=0 and poly[j]==-1):
                new =  int(poly[i][0][0])
                corners.append(corners[int(poly[i][0][0])])
                poly[j] = poly[i]
                continue
            if(poly[i]>=0 and poly[j]>=0):
                if (poly[i]==poly[j]):
                    corners = np.append(corners[int(poly[i][0][0])])
                    continue
                for s in corners[poly[j]].size:
                    corners.append(corners[poly[j]][s])
                clear = corners[poly[j]]
                corners.remove(clear)
                poly[j] = poly[i]
                continue

The thing is, conversion is one thing, efficient is another. And then you have this: https://www.google.com/search?q=python+cs+c%2B%2B+speed

I can't guess why the move to Python, that's not revealed yet. I know folk learn it as they are new to programming and it has some attraction for ease of learning.

My bet is the overall speed should be slower. Why has been the topic for years so I'll forgo that.

whene i say efficient i mean the code not the speed of run , enyway thank u for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.