[Anfänger] Opencv Konturen erkennen
-
Hallo c-Community,
ich bin gerade dabei mich in OpenCV ein. Derzeit möchte ich im folgenden Bild http://www.google.com/imgres?imgurl=http://www.mathematische-basteleien.de/kreise_im_kreis24.jpg&imgrefurl=http://www.mathematische-basteleien.de/kreise_im_kreis.htm&usg=__XeH4eAuT4Uy3UJR-H9KOoSS6sD0=&h=282&w=292&sz=14&hl=de&start=0&zoom=1&tbnid=JYZZZFsAiUKvoM:&tbnh=110&tbnw=114&ei=VqDoTbiWOYfo-gaFwaTEDw&prev=/search%3Fq%3DKreis%26hl%3Dde%26client%3Dubuntu%26hs%3DtzQ%26sa%3DX%26channel%3Dfs%26biw%3D1280%26bih%3D539%26tbm%3Disch%26prmd%3Divns&itbs=1&iact=rc&dur=563&page=1&ndsp=24&ved=1t:429,r:14,s:0&tx=30&ty=34&biw=1280&bih=539Die Anzahl an Kreisen und später die Farben bestimmen. Dazu habe ich mir folgenden Code erstellt anhand des contour.c Beispiels welches OpenCv beiliegt.
Hier mein Quellcode:
#include "/home/theghostod/Programmierung/OpenCV-2.0.0/include/opencv/cv.h" #include "/home/theghostod/Programmierung/OpenCV-2.0.0/include/opencv/highgui.h" #include <stdio.h> #include "error.h" #include <stdarg.h> #include "helpfunctions.h" #include "math.h" IplImage* img = 0; int levels = 3; CvSeq* contours = 0; void update_Contour_Level(int pos) { IplImage* destImg = cvCreateImage(cvGetSize(img), 8, 3); cvZero(destImg); cvDrawContours(destImg, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), levels, 3, CV_AA, cvPoint(0,0) ); cvShowImage("OpenCV-Function-Test_Contours", destImg); cvReleaseImage(&destImg); } int main(int argc, char **argv) { if (argc <= 1) { Error_Missing_File(); } else { img = cvLoadImage(argv[1],1); if (!img) { printf("Error:\tImage %s not found\n", argv[1]); return -1; } cvNamedWindow("OpenCV-Function-Test", CV_WINDOW_AUTOSIZE); cvShowImage("OpenCV-Function-Test", img); CvMemStorage* storage = cvCreateMemStorage(0); IplImage* tempImg = cvCreateImage(cvGetSize(img), 8, 1); cvCvtColor(img, tempImg, CV_BGR2GRAY); cvNamedWindow("OpenCV-Function-Test_Gray", CV_WINDOW_AUTOSIZE); cvShowImage("OpenCV-Function-Test_Gray", tempImg); cvFindContours(tempImg, storage, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); contours = cvApproxPoly( contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, 3, 1 ); cvNamedWindow("OpenCV-Function-Test_Contours", CV_WINDOW_AUTOSIZE); cvCreateTrackbar("level", "OpenCV-Function-Test_Contours", &levels, 100, update_Contour_Level); update_Contour_Level(0); cvWaitKey(0); cvDestroyWindow("OpenCV-Function-Test"); cvDestroyWindow("OpenCV-Function-Test_Gray"); cvReleaseMemStorage(&storage); cvReleaseImage(&img); cvReleaseImage(&tempImg); } return 0; }
Leider kann ich keine Konturen darstellen (Bild hat einen roten Rand (äußere Kontur wahrscheinlich) und der Rest ist schwarz) und weiß derzeit nicht woran dies liegt. Sieht jemand den Fehler (kann ja nur ein grundlegender sein.
Vielen Dank
mirrowwinger
-
Wollte nochmal fragen, ob sich jemand mit dem Problem auskennt. Habe selber noch keine Lösung gefunden.
Vielen Dank