Objekt innerhalb Bildes zu isolieren, habe ich ein Bild wie:OpenCV 2.3 C - Wie
Ich mag die schwarzen Zeilen und Spalten um die Nummer zu entfernen. So wollen ich, dass das Ergebnis:
ich versuche dies:
void findX(IplImage* imgSrc,int* min, int* max){
int i;
int minFound=0;
CvMat data;
CvScalar maxVal=cvRealScalar(imgSrc->width * 255);
CvScalar val=cvRealScalar(0);
//For each col sum, if sum < width*255 then we find the min
//then continue to end to search the max, if sum< width*255 then is new max
for (i=0; i< imgSrc->width; i++){
cvGetCol(imgSrc, &data, i);
val= cvSum(&data);
if(val.val[0] < maxVal.val[0]){
*max= i;
if(!minFound){
*min= i;
minFound= 1;
}
}
}
}
void findY(IplImage* imgSrc,int* min, int* max){
int i;
int minFound=0;
CvMat data;
CvScalar maxVal=cvRealScalar(imgSrc->width * 255);
CvScalar val=cvRealScalar(0);
//For each col sum, if sum < width*255 then we find the min
//then continue to end to search the max, if sum< width*255 then is new max
for (i=0; i< imgSrc->height; i++){
cvGetRow(imgSrc, &data, i);
val= cvSum(&data);
if(val.val[0] < maxVal.val[0]){
*max=i;
if(!minFound){
*min= i;
minFound= 1;
}
}
}
}
CvRect findBB(IplImage* imgSrc){
CvRect aux;
int xmin, xmax, ymin, ymax;
xmin=xmax=ymin=ymax=0;
findX(imgSrc, &xmin, &xmax);
findY(imgSrc, &ymin, &ymax);
aux=cvRect(xmin, ymin, xmax-xmin, ymax-ymin);
//printf("BB: %d,%d - %d,%d\n", aux.x, aux.y, aux.width, aux.height);
return aux;
}
So verwende ich:
IplImage *my_image = cvLoad....
CvRect bb = findBB(my_image);
IplImage *new_image = cvCreateImage(cvSize(bb.width,bb.height), my_image->depth, 1);
cvShowImage("test",new_image);
es nicht gut funktioniert, weil ich versuche, um zu prüfen, ob in einem neuen Bild schwarze Zeilen oder Spalten vorhanden sind und diese vorhanden sind. Was kann ich tun? kann mir jemand helfen?
Ihr Bild hat nur eine Nummer, also bin ich mir nicht sicher, was Sie mit schwarzen Zeilen und Spalten "rund" die Zahl meinen. – karlphillip
sorry für mein Englisch wieder .. für "rund" ich meine die Zeilen und Spalten mit allen Wert schwarz (0) in der Nähe der Nummer – JackTurky
Humm .. ich denke, Sie sprechen auf der Pixel-Ebene. Denken Sie jetzt darüber nach, wenn Sie dieses Bild umkehren, wird alles, was schwarz ist, weiß und die Zahl selbst schwarz. Wäre das nicht besser? – karlphillip