Elementfunktion sei in Klasse nicht deklariert



  • Dann hier nun die fehlende .cpp
    Tut mir leid, dass ihr immer auf Anfrage dazu kommt. Ich wollte mich an die Forenhinweise (kurzen Code) halten.

    Zeile 385 und 386 stehen die beiden 😉

    #include "image.h"
    
    /*
    #################################
    #				#
    # Konstruktoren			#
    #				#
    #################################
    */
    
    IMAGE::IMAGE(){
    bps = 0;
    }
    
    IMAGE::IMAGE(const char* filename){
     image = TIFFOpen(filename, "r");
     bps = new uint16;
     *bps = ReadBPS();
     spp = new uint16;
     *spp = ReadSPP();
     rowsps = new unsigned long;
     *rowsps = ReadROWSPS();
     width = new uint32;
     *width = ReadWIDTH();
     height = new uint32;
     *height = ReadLENGTH();
     scanlineSize = new int;
     *scanlineSize = ReadSCANLINESIZE();
     bufferSize = new unsigned long;
     *bufferSize = ReadBUFFERSIZE();
     if(image == NULL){//überprüft ob das Bild geöffnet werden kann
      fprintf(stderr, "Bilddatei konnte nicht geoffnet werden\n");
      exit(42);
     }
     buffer = new uint16[*bufferSize+1];
    
     ReadIMAGEDATA();
     TIFFClose(image);
    }
    
    /*
    #################################
    #				#
    # Kopierkonstruktor		#
    #				#
    #################################
    */
    
    IMAGE::IMAGE(const IMAGE & img){
    // image = TIFFOpen("newFile.tif", "w");
     bps = new uint16;
     *bps = *(img.bps);
     spp = new uint16;
     *spp = *(img.spp);
     rowsps = new unsigned long;
     *rowsps = *(img.rowsps);
     width = new uint32;
     *width = *(img.width);
     height = new uint32;
     *height = *(img.height);
     scanlineSize = new int;
     *scanlineSize = *(img.scanlineSize);
     bufferSize = new unsigned long;
     *bufferSize = *(img.bufferSize);
    
     buffer = new uint16[*bufferSize+1];
     for(unsigned int i=0; i < *bufferSize; i++) buffer[i] = img.buffer[i];
    }
    
    /*
    #################################
    #				#
    # Lese - Funktionen		#
    #				#
    #################################
    */
    
    uint16 IMAGE::ReadBPS() const{
     if(TIFFGetField(this->image, TIFFTAG_BITSPERSAMPLE, this->bps) == 0){
      fprintf(stderr, "Fehler beim einesen von bps");
      exit(42);
     }
     return *bps;
    }
    
    uint16 IMAGE::ReadSPP() const{
    
     if(TIFFGetField(this->image, TIFFTAG_SAMPLESPERPIXEL, this->spp) == 0){
      fprintf(stderr, "Fehler beim einlesen von spp");
      exit(42);
     }
     return *spp;
    }
    
    unsigned long int IMAGE::ReadROWSPS() const{
    
     if(TIFFGetField(this->image, TIFFTAG_ROWSPERSTRIP, this->rowsps) == 0){
      fprintf(stderr, "Fehler beim einlesen von rowsps");
      exit(42);
     }
     return *rowsps;
    }
    
    uint32 IMAGE::ReadWIDTH() const{
    
     if(TIFFGetField(this->image, TIFFTAG_IMAGEWIDTH, this->width) == 0){
      fprintf(stderr, "Fehler beim einlesen von width");
      exit(42);
     }
     return *width;
    }
    
    uint32 IMAGE::ReadLENGTH() const{
    
     if(TIFFGetField(this->image, TIFFTAG_IMAGELENGTH, this->height) == 0){
      fprintf(stderr, "Fehler beim einlesen von width");
      exit(42);
     }
     return *height;
    }
    
    unsigned long IMAGE::ReadBUFFERSIZE() const{
    
     unsigned long *tmp;
     tmp = new unsigned long;
     *tmp = TIFFNumberOfStrips(this->image) * TIFFStripSize(this->image);
     return *tmp;
    }
    
    //Notiz im Testfall: stripMax=1536 und stripSize=3840 (also 2*width)
    void IMAGE::ReadIMAGEDATA() const{
    
     int stripMax = TIFFNumberOfStrips(this->image);
     tsize_t stripSize = TIFFStripSize(this->image);
     unsigned long result = 0;
     unsigned long imageOffset = 0;
    
     fprintf(stderr, "stripMax= %i stripSize= %i", stripMax, stripSize);
    
     for(int stripCount = 0; stripCount < stripMax; stripCount++){
      if((result = TIFFReadEncodedStrip(this->image, stripCount, this->buffer + imageOffset, stripSize)) == -1){
       fprintf(stderr, "Fehler strip Anzahl %d\n", stripCount);
       exit(42);
      }
      imageOffset += result;
     }
     fprintf(stderr, "imageOffset= %lu", imageOffset);
    }
    
    /*
    #################################
    #				#
    # Ausgabe - Funktionen		#
    #				#
    #################################
    */
    
    //Dient zum testen (überprüfen, ob auch richtig eingelesen worden ist)
    void IMAGE::PrintHeaderData(){
     fprintf(stderr, "Width=%u Height=%u bps=%i spp=%i rowsps=%lu scanlineSize=%i bufferSize=%lu\n", *this->width, *this->height, *this->bps, *this->spp, *this->rowsps, *this->scanlineSize, *this->bufferSize);
    // fprintf(stderr, "ImageOffset=%lu StripSize=%i\n", imageOffset, stripSize);
    }
    
    //Dient zum testen (überprüfen, ob auch richtig eingelesen worden ist)
    //Aenderung vorgenommen: count < bufferSize -> count < 8
    void IMAGE::PrintImageData(){
     for(unsigned long count = 0; count < 8; count++){ 
      fprintf(stderr, "%02x ", buffer[count]); 
     }
    }
    
    void IMAGE::CreateImage(){
     TIFF* out = TIFFOpen("myFile.tif","w");
     uint16* buf = NULL;
    // char* img = new char[(*this->width)*(*this->height)*(*this->spp)];
     tsize_t linebytes = (*this->spp)*(*this->width);
    
     TIFFSetField(out, TIFFTAG_IMAGEWIDTH, *this->width);
     TIFFSetField(out, TIFFTAG_IMAGELENGTH, *this->height);
     TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, *this->spp);
     TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, *this->bps);
     TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
     TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
     TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
     TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, (*this->width)*(*this->spp)));
    
     if(TIFFScanlineSize(out) == linebytes) 
      buf = (uint16*)_TIFFmalloc(linebytes);
     else buf=(uint16*)_TIFFmalloc(*this->scanlineSize);
    
     for(uint32 row=0; row < *this->height; row++){
      for(int i=0; i<(*this->width); i++){ 
       buf[i] = buffer[i+row*2*(*width)];
      }
      TIFFWriteScanline(out, buf, row, 0);
     }
    
     (void) TIFFClose(out);
     if(buf) _TIFFfree(buf);
    }
    
    /*
    void IMAGE::CreateImage(){
    
     TIFF* out = TIFFOpen("myFile.tif","w");
    
     TIFFSetField(out, TIFFTAG_IMAGEWIDTH, *this->width);
     TIFFSetField(out, TIFFTAG_IMAGELENGTH, *this->height);
     TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, *this->spp);
     TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, *this->bps);
     TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
     TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
     TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
     TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, (*this->bps)*(*this->width)*2));
     TIFFSetField(out, TIFFTAG_FILLORDER, 1);
    
     TIFFWriteEncodedStrip(out, 0, this->buffer, 2*(*this->width) * (*this->height));
    
     (void) TIFFClose(out);
    }
    */
    /*
    #################################
    #				#
    # Bild - Operationen		#
    #				#
    #################################
    */
    
    void
    IMAGE::schwarzZuWeiss(IMAGE &inputImg){
     int H = *inputImg.height*2;
     int W = *inputImg.width;
     for(int h=0; h<H; h++){
      for(int w=0; w<W; w++){
       if(inputImg.buffer[w+h*W] == 0x0000)
        this->buffer[w+h*W] = 0xffff;
      }
     } 
    }
    
    void
    IMAGE::berandung(IMAGE &inputImg){
     int H = *inputImg.height*2;
     int W = *inputImg.width;
     for(int h=0; h<H; h++){
      for(int w=0; w<W; w++){
       if((w==0)||(h==0)||(w==W-1)||(h==H-1))
        this->buffer[w+h*W] = pow(2, (*inputImg.bps)-1);
      }
     }
    }
    
    void 
    IMAGE::glaettung(IMAGE &inputImg){
     int H = inputImg.GetLENGTH();
     int W = inputImg.GetWIDTH();
     uint16 m = 0;
    
     for(int h = 1; h < 2*H-1; h++){
      for(int w = 1; w < (W-1); w++){
       for(int x = -1; x < 2; x++){
        for(int y = -1; y < 2; y++){ //w+h*W + 2*x + y*W
         if((x!=0) || (y!=0)) m += inputImg.GetBufferValue(w+h*W + x + y*W);
         }
       }
       m = m / 8;
       if(inputImg.GetBufferValue(w+h*W) > m) this->SetBufferValue(m, w+h*W);
       m = 0;
      }
     }
    }
    
    unsigned long
    IMAGE::mittelwert(){
     unsigned long mittelwertZeile=0;
     unsigned long mittel=0;
     int H = *this->height*2;
     int W = *this->width;
     for(int h=0; h<H*2; h++){
      for(int w=0; w<W; w++){
       mittelwertZeile += this->buffer[w+h*W];
      }
      mittelwertZeile = mittelwertZeile/W;
      mittel += mittelwertZeile;
      mittelwertZeile =0;
     }
     mittel = mittel / H;
     return mittel;
    }
    
    void 
    IMAGE::grauwertSchwaerzen(IMAGE &inputImg, uint16 VF){
     for(unsigned int i=0; i<inputImg.GetBufferSize(); i++){
      if(inputImg.GetBufferValue(i) > (pow(2,*inputImg.bps -1)-VF)) this->SetBufferValue(0x0000,i);
     }
    }
    
    void 
    IMAGE::grauwertVerschiebung(IMAGE &inputImg, uint16 VF){
     for(unsigned int i=0; i<inputImg.GetBufferSize(); i++){
       if(inputImg.GetBufferValue(i) > (pow(2,*inputImg.bps)-VF)) this->SetBufferValue(0x0000,i);
       else this->SetBufferValue(inputImg.GetBufferValue(i)+VF, i);
     }
    }
    
    void
    IMAGE::grauwertStreckung(IMAGE &inputImg){
     uint16 Max = inputImg.SearchMax();
     uint16 long Min = inputImg.SearchMin();
    
     for(unsigned int i=0; i<*inputImg.bufferSize; i++){
      this->buffer[i] = ( (inputImg.buffer[i] - Min) * (pow(2, *inputImg.bps) -1) )/(Max-Min);
     }
    }
    
    void
    IMAGE::Gauss_Tiefpass(IMAGE& inputImg){
     int H = inputImg.GetLENGTH();
     int W = inputImg.GetWIDTH();
     int m = 0;
    
     for(int h = 1; h < 2*H-1; h++){
      for(int w = 1; w < (W-1)*2; w++){
       for(int x = -1; x < 2; x++){
        for(int y = -1; y < 2; y++){ 
         if((x==0)&&(y==0)) m += inputImg.GetBufferValue(w+h*W + x + y*W) *2*2;
         if((x!=0)&&(y==0)) m += inputImg.GetBufferValue(w+h*W + x + y*W) *2;
         if((x==0)&&(y!=0)) m += inputImg.GetBufferValue(w+h*W + x + y*W) *2;
         else m += inputImg.GetBufferValue(w+h*W + x + y*W) ;
        }
       }
       m=m/16;
       this->SetBufferValue(m, w+h*W);
       m=0;
      }
     }
    }
    
    void
    IMAGE::Sobel(IMAGE &inputImg){
     int H = *inputImg.height*2;
     int W = *inputImg.width;
     uint16 h_x=0,h_y=0;
     for(int h = 1; h < H-1; h++){
      for(int w = 1; w < W-1; w++){
       h_x = inputImg.H_X(w+h*W);
       h_y = inputImg.H_Y(w+h*W);
       this->buffer[w+h*W] = sqrt(h_x*h_x + h_y*h_y);
      }
     }
    }
    void
    IMAGE::Sobel_Y(IMAGE &inputImg){
     int H = *inputImg.height*2;
     int W = *inputImg.width;
     for(int h = 1; h < H-1; h++){
      for(int w = 1; w < W-1; w++){
       this->buffer[w+h*W] = inputImg.H_Y(w+h*W);
      }
     }
    }
    
    void
    IMAGE::Sobel_X(IMAGE &inputImg){
     int H = *inputImg.height*2;
     int W = *inputImg.width;
     for(int h = 1; h < H-1; h++){
      for(int w = 1; w < W-1; w++){
       this->buffer[w+h*W] = inputImg.H_X(w+h*W);
      }
     }
    }
    
    uint16
    IMAGE::H_Y(int i){
     uint16 h_y = 0;
     for(int x = -1; x < 2; x++){
      for(int y = -1; y < 2; y++){ 
       if((x!=0)&&(y<0)) h_y += this->buffer[i+x+y*(*this->width)];
       if((x==0)&&(y<0)) h_y += this->buffer[i+x+y*(*this->width)] *2 ;
       if((x!=0)&&(y>0)) h_y += this->buffer[i+x+y*(*this->width)] *(-1);
       if((x==0)&&(y>0)) h_y += this->buffer[i+x+y*(*this->width)] *(-2) ; 
      }
     }
     h_y=h_y/8;
     return h_y;
    }
    
    uint16
    IMAGE::H_X(int i){
     uint16 h_x = 0;
     for(int x = -1; x < 2; x++){
      for(int y = -1; y < 2; y++){ 
       if((x<0)&&(y!=0)) h_x += this->buffer[i+x+y*(*this->width)];
       if((x<0)&&(y==0)) h_x += this->buffer[i+x+y*(*this->width)] *2 ;
       if((x>0)&&(y!=0)) h_x += this->buffer[i+x+y*(*this->width)] *(-1);
       if((x>0)&&(y==0)) h_x += this->buffer[i+x+y*(*this->width)] *(-2) ; 
      }
     }
     h_x=h_x/8;
     return h_x;
    }
    
    void IMAGE::invert(){}
    void IMAGE::test(){}
    
    /*
    #################################
    #				#
    # Hilfsfunktionen		#
    #				#
    #################################
    */
    
    uint16
    IMAGE::SearchMax(){
     uint16 max = 0;
     for(unsigned int i=0; i<this->GetBufferSize(); i++){
      if(this->buffer[i] > max) max=this->buffer[i];
      if(max==(pow(2, this->GetBPS()) - 1)) break;
     }
    // printf("\nMax= %u\n", max);
     return max;
    }
    
    uint16
    IMAGE::SearchMin(){
     uint16 min = pow(2,this->GetBPS()) -1;
     for(unsigned int i=0; i<this->GetBufferSize(); i++){
      if(this->buffer[i] < min) min = this->buffer[i];
      if(min==0) break;
     }
    // printf("\nMin= %u\n", min);
     return min;
    }
    
    /*### NOTIZEN ###*/
    /*
    -> 8er-Nachbarschaft
    for(int h = 1; h < 2*H-1; h++){
     for(int w = 1; w < W-1; w++){
      for(int x = -1; x < 2; x++){
       for(int y = -1; y < 2; y++){ 
    
       }
      }
     }
    }
    
    */
    
    /*### SICHERUNG ###*/
    


  • verzeiht bitte meinen fehler
    405 und 406 meinte ich



  • Xx_Mephisto_xX schrieb:

    uint16 long
    

    Was soll das denn sein?



  • Naja, erstens meinte ich, dass du den Inhalt der Funktionen ruhig rauslassen kannst, statt

    IMAGE::IMAGE(const IMAGE & img){
    // image = TIFFOpen("newFile.tif", "w");
     bps = new uint16;
     *bps = *(img.bps);
     spp = new uint16;
     *spp = *(img.spp);
     rowsps = new unsigned long;
     *rowsps = *(img.rowsps);
     width = new uint32;
     *width = *(img.width);
     height = new uint32;
     *height = *(img.height);
     scanlineSize = new int;
     *scanlineSize = *(img.scanlineSize);
     bufferSize = new unsigned long;
     *bufferSize = *(img.bufferSize);
    
     buffer = new uint16[*bufferSize+1];
     for(unsigned int i=0; i < *bufferSize; i++) buffer[i] = img.buffer[i];
    }
    

    also

    IMAGE::IMAGE(const IMAGE & img)
    {
    }
    

    Aber was falsches kann ich nicht erkennen. Mein Compiler zeigt mir (zu Recht) tausende Fehler, weil er die Hälfte von deinen Funktionen und Klassen (der Tiff kram) natürlich nicht kennt.



  • UInt16 sind ganze Zahlen ohne Vorzeichen mit Werten zwischen 0 und 65535

    habe ich irgendwo "uint16 long" stehen? 😮



  • Nein eigentlich nicht. Ich weis nicht wie er daauf kommt



  • Zeile 310. Seh ich schon Ufos?



  • @Skym0sh0:

    Tut mir leid, als ich deinen Beitrag gelesen hatte, war es schon zu spät 😞
    Ja ich benutze die Libtiff



  • @MFK

    Vielen Dank, dass habe ich gleich mal geändert 😉
    (weiß garnicht, warum da nicht mal eine Warnung kam)

    Damit änderte sich aber leider nicht mein Problem 😞



  • MFK schrieb:

    Zeile 310. Seh ich schon Ufos?

    Möp. oO

    Ich hab per Textsuche das dezent überlesen 😣



  • Nur mal so aus der Luft gegriffen:

    Könnte es sein, dass du dein Projekt kompiliert hast, bevor du test() und invert() implementiert hast?

    Ansonsten kann ich mir nichts anderes vorstellen was an dem Code falsch sein könnte, sodass der Compiler eine derartige Fehlermeldung ausspuckt.



  • @hmhmhm:

    Also ich habe jetzt jede einzelne Komponente (ob .h oder .cpp) gespeichert und alles nochmal versucht zu kompilieren. Aber die Fehlermeldung ist leider nach wie vor noch die selbe. 😞



  • 'tschuldigung, umgekehrt:

    *könnte es sein, dass du test() und invert() implementiert hast, bevor du sie in der klasse deklariert hast?

    Und "uint16 long" hat echt keine Fehlermeldung rausgeworfen? Welche Compiler-Version von G++ hastn?



  • Xx_Mephisto_xX schrieb:

    Damit änderte sich aber leider nicht mein Problem 😞

    Wenn ich Header und Implementierung in ein File kopiere, kann ich (nachdem ich einen c'tor nach hinten in der Datei verschoben habe) alles kompilieren.

    Kompilierst Du das richtige? 🙂



  • Also meine gxx-Version:
    g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

    und ich kompiliere wie folgt:

    g++ -Wall main.cpp image.cpp hist.cpp -ltiff -o ausgabe



  • Das ist zwar ein wenig wie Schnitzeljagd, aber bau doch mal einen ganz offensichtlichen Fehler ein.
    Z.B. ein unmotiviertes

    SCHIRSCHADENDUDEL

    mitten im Quelltext des Headers. Wenn das wirklich der Header ist, der eingebunden wird, fällt Dir das auf die Füsse.
    (Und ich denke der gepostete Header ist nicht der, den der Compiler sieht.)



  • g++ meinte ich statt gxx ^^

    Kann es sein, dass ich beim includieren etwas falsch mache?
    ich includiere "image.h" sowohl in der main.cpp als auch in der hist.h

    hier die hist.h:

    #ifndef HIST_H
    #define HIST_H
    
    #include "image.h"
    
    class HIST{
    public:
    
    HIST(IMAGE&);
    
     unsigned int GetHistBufferValue(int);
     unsigned int GetHistSize();
     int FindMax();
    
     void PrintHist();
    
     void test();
    
    private:
     IMAGE* img;
     unsigned long histSize;
     unsigned long *histBuffer;
    };
    
    #endif
    

    und die main.cpp (besteht mittlerweile aus auskommentierten Quelltexten)

    #include <iostream>
    #include <stdio.h>
    //#include <string.h>
    
    #include "image.h"
    #include "hist.h"
    
    using namespace std;
    
    int main(){
    return 0;
    }
    


  • SCHIRSCHADENDUDEL springt nun mitten aus meiner classIMAGE hervor 😉

    g++ -Wall main.cpp image.cpp hist.cpp -ltiff -o ausgabe
    In file included from main.cpp:5:0:
    image.h:83:1: Fehler: »SCHIRSCHADENDUDEL« bezeichnet keinen Typ
    image.cpp:405:20: Fehler: keine Elementfunktion »void IMAGE::invert()« in Klasse »IMAGE« deklariert
    image.cpp:406:18: Fehler: keine Elementfunktion »void IMAGE::test()« in Klasse »IMAGE« deklariert
    In file included from hist.h:4:0,
                     from hist.cpp:1:
    image.h:83:1: Fehler: »SCHIRSCHADENDUDEL« bezeichnet keinen Typ
    make: *** [all] Fehler 1
    


  • Solange du Includeguards hast, sollte beim Inkludieren nichts falsches passieren, und die hast du ja.

    Hast du zyklische Abhängigkeiten?
    A inkludiert B und umgekehrt (eventuell über mehrere Indirektionen)



  • Leider kommt jetzt meine c++-Unkenntnis zum tragen.
    Was versteht man unter einer Indirektion?
    Ich hatte mal etwas von einer Überladung des -> Operators gelesen. Ist es das?

    folgende include-beziehungen habe ich derzeit:

    main includiert : - image - hist
    hist includiert : - image

    Also wäre die Antwort A includiert B aber nicht umgekehrt


Anmelden zum Antworten