2014-05-10 15 views
6

से मैट बनाएं मैं कंप्यूटर दृष्टि और ओपनसीवी लाइब्रेरी के लिए बेहद नया हूं।वेक्टर <point2f>

मैंने प्वाइंट 2fs के वेक्टर से नई छवि बनाने के तरीके को खोजने के लिए चारों ओर कुछ गुगल किया है और काम करने वाले किसी भी उदाहरण को नहीं मिला है। मैंने vector<Point> to Mat देखा है लेकिन जब मैं उन उदाहरणों का उपयोग करता हूं तो मुझे हमेशा त्रुटियां मिलती हैं।

मैं this उदाहरण से काम कर रहा हूं और किसी भी मदद की सराहना की जाएगी।

कोड: मैं occludedSquare में गुजरता हूं।

resize(occludedSquare, occludedSquare, Size(0, 0), 0.5, 0.5); 

    Mat occludedSquare8u; 
    cvtColor(occludedSquare, occludedSquare8u, CV_BGR2GRAY); 

    //convert to a binary image. pixel values greater than 200 turn to white. otherwize black 
    Mat thresh; 
    threshold(occludedSquare8u, thresh, 170.0, 255.0, THRESH_BINARY); 



    GaussianBlur(thresh, thresh, Size(7, 7), 2.0, 2.0); 

    //Do edge detection 
    Mat edges; 
    Canny(thresh, edges, 45.0, 160.0, 3); 

    //Do straight line detection 
    vector<Vec2f> lines; 
    HoughLines(edges, lines, 1.5, CV_PI/180, 50, 0, 0); 

    //imshow("thresholded", edges); 


    cout << "Detected " << lines.size() << " lines." << endl; 

    // compute the intersection from the lines detected... 
    vector<Point2f> intersections; 
    for(size_t i = 0; i < lines.size(); i++) 
    { 
     for(size_t j = 0; j < lines.size(); j++) 
     { 
      Vec2f line1 = lines[i]; 
      Vec2f line2 = lines[j]; 
      if(acceptLinePair(line1, line2, CV_PI/32)) 
      { 
       Point2f intersection = computeIntersect(line1, line2); 
       intersections.push_back(intersection); 
      } 
     } 

    } 

    if(intersections.size() > 0) 
    { 
     vector<Point2f>::iterator i; 
     for(i = intersections.begin(); i != intersections.end(); ++i) 
     { 
      cout << "Intersection is " << i->x << ", " << i->y << endl; 
      circle(occludedSquare8u, *i, 1, Scalar(0, 255, 0), 3); 
     } 
    } 

//Make new matrix bounded by the intersections 
... 
imshow("localized", localized); 
+0

मैं अंक ले जाना चाहते हैं के बहुत सारे मैं एक बनाने के लिए कर रहे हैं आरओआई और वहां से एक नया मैट्रिक्स बनाते हैं। क्या यह और स्पष्ट है? मुझे सच में यकीन नहीं है कि मैट्रिक्स में अंक और ड्राइंग पॉइंट्स बनाने के बीच क्या अंतर है। – myselfesteem

उत्तर

9

होना चाहिए के रूप में सरल रूप में

std::vector<cv::Point2f> points; 
cv::Mat image(points); 
//or 
cv::Mat image = cv::Mat(points) 

शायद भ्रम की स्थिति है कि एक सीवी :: चटाई चैनलों की एक छवि width*height*number है लेकिन यह भी एक गणितीय मैट्रिक्स, rows*columns*other dimension

यदि आप 'एन' 2 डी बिंदुओं के वेक्टर से एक मैट बनाते हैं तो यह 'एन' पंक्ति मैट्रिक्स द्वारा 2 कॉलम बनाएगा। आप इसे एक ऐसे फ़ंक्शन में पास कर रहे हैं जो किसी छवि की अपेक्षा करता है।

यदि आपके पास सिर्फ 2 डी अंक का बिखरा हुआ सेट है और उन्हें एक छवि के रूप में प्रदर्शित करना चाहते हैं तो आपको एक खाली सीवी बनाने की आवश्यकता है :: बड़े आकार के मट (जो भी आपका अधिकतम एक्स, वाई बिंदु है) और फिर ड्रा ड्राइंग कार्यों http://docs.opencv.org/doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.html

का उपयोग कर डॉट्स आप सिर्फ उन बिंदु पर पिक्सेल मान सेट करना चाहते हैं opencv सेटिंग पिक्सेल मूल्यों के लिए एसओ खोज निर्देशांक है, वहाँ जवाब

+3

मुझे रनटाइम त्रुटि मिलती है "cvConvertImage में चैनलों की खराब संख्या (स्रोत छवि में 1, 3 या 4 चैनल होना चाहिए) ...)" इन दोनों विकल्पों के लिए। – myselfesteem

+0

मैं समस्या कथन में अस्पष्ट हो सकता था, लेकिन मैंने इसे आरओआई बनाकर तय किया और इसके बाद मेरे मैट्रिक्स को फसल कर दिया। मैंने सबसे छोटा एक्स और वाई मान ढूंढकर आरओआई बनाया। तब मैं ऊंचाई और चौड़ाई की गणना कर सकता था। मैं आपको सही उत्तर के रूप में चिह्नित कर रहा हूं क्योंकि आपने मुझे सही रास्ते पर ले जाया था। – myselfesteem

संबंधित मुद्दे