मैं OpenCV 2.4.2 में समोच्च का पता लगाने के साथ आरंभ करने के लिए कोशिश कर रहा हूँ। इस अंत में, मैंने ओपनसीवी के लिए एक प्रोजेक्ट स्थापित किया और documentation में मिले पूरे उदाहरण कोड की प्रतिलिपि बनाई। भविष्य में संदर्भ के लिए, यहाँ कोड है:OpenCV उदाहरण कोड: वेक्टर आवंटन रद्द मुद्दा
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
Mat src; Mat src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);
/// Function header
void thresh_callback(int, void*);
/** @function main */
int main(int argc, char** argv)
{
/// Load source image and convert it to gray
src = imread(argv[1], 1);
/// Convert image to gray and blur it
cvtColor(src, src_gray, CV_BGR2GRAY);
blur(src_gray, src_gray, Size(3,3));
/// Create Window
char* source_window = "Source";
namedWindow(source_window, CV_WINDOW_AUTOSIZE);
imshow(source_window, src);
createTrackbar(" Canny thresh:", "Source", &thresh, max_thresh, thresh_callback);
thresh_callback(0, 0);
waitKey(0);
return(0);
}
/** @function thresh_callback */
void thresh_callback(int, void*)
{
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// Detect edges using canny
Canny(src_gray, canny_output, thresh, thresh*2, 3);
/// Find contours
findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// Draw contours
Mat drawing = Mat::zeros(canny_output.size(), CV_8UC3);
for(int i = 0; i< contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255));
drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point());
}
/// Show in a window
namedWindow("Contours", CV_WINDOW_AUTOSIZE);
imshow("Contours", drawing);
contours.clear(); // Error!!
}
यह दृश्य स्टूडियो 11 आर सी (विंडोज 7 SP1) में ठीक संकलित है, लेकिन मैं thresh_callback
समारोह के अंत में कोई त्रुटि मिलती है। यहाँ स्टैकट्रेस है:
msvcr110d.dll!_CrtIsValidHeapPointer(const void * pUserData) Line 2036
msvcr110d.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1322
msvcr110d.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1265
msvcr110d.dll!operator delete(void * pUserData) Line 54
std::allocator<cv::Point_<int> >::deallocate(cv::Point_<int> * _Ptr, unsigned int __formal) Line 586
std::_Wrap_alloc<std::allocator<cv::Point_<int> > >::deallocate(cv::Point_<int> * _Ptr, unsigned int _Count) Line 888
std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > >::_Tidy() Line 1542
std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > >::~vector<cv::Point_<int>,std::allocator<cv::Point_<int> > >() Line 901
std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > >::`scalar deleting destructor'(unsigned int)
std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > >::destroy<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > >(std::<cv::Point_<int>,std::allocator<cv::Point_<int> > > * _Ptr) Line 624
std::allocator_traits<std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > > >::destroy<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > >(std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > > & _Al, std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > * _Ptr)758
std::_Wrap_alloc<std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > > >::destroy<std::vector<cv::Point_<int>,std::allocator<cv::Poin> > > >(std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > * _Ptr) Line 909
std::_Destroy_range<std::_Wrap_alloc<std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > > > >(std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > * _First, std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > * _Last, std::_Wrap_alloc<std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::<int> > > > > & _Al, std::_Nonscalar_ptr_iterator_tag __formal) Line 89
std::_Destroy_range<std::_Wrap_alloc<std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > > > >(std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > * _First, std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > * _Last, std::_Wrap_alloc<std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::<int> > > > > & _Al) Line 80
std::vector<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > >,std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> >::_Destroy(std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > * _First, std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > * _Last) Line 1480
std::vector<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > >,std::allocator<std::vector<cv::Point_<int>,std::allocator<cv::Point_<int> > > > >::c Line 1416
thresh_callback(int __formal, void * __formal) Line 143
opencv_highgui242d.dll!icvUpdateTrackbar(CvTrackbar * trackbar, int pos) Line 1938
opencv_highgui242d.dll!HGToolbarProc(HWND__ * hwnd, unsigned int uMsg, unsigned int wParam, long lParam) Line 1982
(ध्यान दें कि वास्तव में मैं है उदाहरण के कोड का एक थोड़ा संशोधित संस्करण, कुछ printf-s, और एक contours.clear()
कॉल, जो लाइन 143 पर है जोड़ा, और जो वेक्टर से चलाता है deallocation [जो फ़ंक्शन के अंत में स्वचालित रूप से होता है] जो कि समस्या का स्रोत प्रतीत होता है। एक ही समस्या सटीक उदाहरण कोड के साथ भी होती है।)
समस्या का विलोपन होना प्रतीत होता है contours
वेक्टर। वही होता है यदि मैं contours.clear()
पर कॉल करने का प्रयास करता हूं। मैंने वीएस डीबगर में चर की सामग्री की जांच की है, लेकिन जहां तक मैं कह सकता हूं वहां असामान्य कुछ भी नहीं है।
मैंने वेक्टर को साफ़ करने की कोशिश की जैसे ही इसकी आवश्यकता नहीं थी (for
लूप के बाद), लेकिन इससे मदद नहीं मिली।
error C1083: Cannot open include file: 'SDKDDKVer.h': No such file or directory (C:\<project path>\targetver.h) (Line 8, Column 1)
IntelliSense: cannot open source file "SDKDDKVer.h" (C:\<project path>\targetver.h) (Line 8, Column 1)
IntelliSense: cannot open source file "windows.h" (C:\<opencv path>\build\include\opencv2\core\operations.hpp (Line 83, Column 3)
किसी भी मदद की बहुत सराहना की जाएगी: मैं यह विजुअल स्टूडियो 10, जो बारी में भी त्रुटि संदेश है कि मुझे बाहर हैं के साथ संकलन नहीं होगा करने के लिए मंच टूलसेट स्विच करने की कोशिश की। कृपया ध्यान दें कि मैं एक सी ++ प्रोग्रामर नहीं हूं: मेरे पास बहुत कम ज्ञान है, और सामान्य रूप से सी ++ प्रोग्रामिंग और देशी प्रोग्रामिंग के साथ भी कम अनुभव है।
संपादित: यह पता चला है कि डिबगर त्रुटि के स्रोत के रूप में गलत लाइन का प्रदर्शन किया। मुझे कॉल स्टैक में देखा जाना चाहिए था कि समस्या वेक्टर के साथ थी>। तो समस्याग्रस्त वेक्टर contours
है, hierarchy
नहीं!
संपादित # 2: मैं भी एक न्यूनतम कोड है कि एक vector<vector<cv::Point> >
बनाता है के साथ समस्या को ठीक करने की कोशिश की, उस में कुछ आइटम डालता है, तो यह साफ करता है, लेकिन मैं समस्या को पुन: नहीं कर सका।
आप, स्पष्ट करने के लिए आकृति आपत्ति की कोई जरूरत नहीं है कि वहाँ सही पता है? यह thresh_callback फ़ंक्शन कॉल के अंत में कचरा-एकत्रित किया जाएगा। क्या आपका कोड इस लाइन के बिना काम करता है? –
@ रेगिसबी .: मेरा मानना है कि मैंने अपने प्रश्न में इसका उल्लेख किया है कि एक ही त्रुटि लाइन के बिना होती है। यहां स्पष्ट रूप से 'contours.clear' को कॉल करने का एकमात्र कारण यह है कि समस्या कहां हो रही है। – ShdNx
'सभी कॉन्फ़िगरेशन -> सामान्य -> प्लेटफ़ॉर्म टूलसेट -> विजुअल स्टूडियो 2010 (v100) 'मेरे लिए हल समस्या। – vkalit