मैंने डेल्फी/लाजर एप्लिकेशन से लोड किए गए समोच्च पहचान के लिए एक साझा लाइब्रेरी बनाई है। मुख्य ऐप, लाइब्रेरी के अंदर एक फ़ंक्शन द्वारा संसाधित होने के लिए एक बिटमैप को पॉइंटर पास करता है।बिटमैप प्रोसेसिंग के लिए ओपनसीवी पॉइंटर
लाइब्रेरी के अंदर फ़ंक्शन यहां है। पैरामीटर "आईएमजी" मेरे बिटमैप के सूचक है।
extern "C" {
void detect_contour(int imgWidth, int imgHeight, unsigned char * img, int &x, int &y, int &w, int &h)
{
Mat threshold_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
Mat src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);
/// Load source image and convert it to gray
Mat src(imgHeight, imgWidth, CV_8UC4);
int idx;
src.data = img;
/// Convert image to gray and blur it
cvtColor(src, src_gray, CV_BGRA2GRAY);
blur(src_gray, src_gray, Size(10,10));
/// Detect edges using Threshold
threshold(src_gray, threshold_output, thresh, 255, THRESH_BINARY);
/// Find contours
findContours(threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// Approximate contours to polygons + get bounding rects and circles
vector<vector<Point> > contours_poly(contours.size());
vector<Rect> boundRect(contours.size());
vector<Point2f>center(contours.size());
vector<float>radius(contours.size());
int lArea = 0;
int lBigger = -1;
for(int i = 0; i < contours.size(); i++)
{
approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);
boundRect[i] = boundingRect(Mat(contours_poly[i]));
if(lArea < boundRect[i].width * boundRect[i].height)
{
lArea = boundRect[i].width * boundRect[i].height;
lBigger = i;
}
}
if(lBigger > -1)
{
x = boundRect[lBigger].x;
y = boundRect[lBigger].y;
w = boundRect[lBigger].width;
h = boundRect[lBigger].height;
}
}
}
डेल्फी की ओर से, मैं इस संरचना की एक सरणी के लिए सूचक गुजर रही है:
TBGRAPixel = packed record
blue, green, red, alpha: byte;
end;
मैं में स्मृति बिटमैप कार्रवाई करने के लिए की जरूरत है, यही कारण है कि मैं लोड नहीं हूँ पुस्तकालय के अंदर से फ़ाइल।
सवाल यह है: क्या यह सीवी :: मैट को बिटमैप असाइन करने का सही तरीका है?
मैं यह पूछता हूं क्योंकि कोड लिनक्स में समस्याओं के बिना काम करता है, लेकिन विंडोज़ पर मिंगव के साथ संकलित विफल रहता है।
नोट: यह इस लाइन पर एक SIGSEGV के साथ विफल:
blur(src_gray, src_gray, Size(10,10));
संपादित करें: SIGSEGV उठाया है केवल अगर मैं रिलीज मोड में OpenCV संकलन, डीबग मोड में यह ठीक काम करता है।
अग्रिम धन्यवाद, लियोनार्डो।
धन्यवाद जोनास। मैंने आपके सुझाव की कोशिश की, और यह लिनक्स पर काम करता है, लेकिन एसआईजीएसईजीवी अभी भी विंडोज़ पर है। – leonardorame