IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

problème avec using namespace cv; dans visual studio


Sujet :

C++

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 41
    Points : 8
    Points
    8
    Par défaut problème avec using namespace cv; dans visual studio
    Bonjour,

    est ce que quelqu'un peu m'expliquer lq methode à effectuer pour corriger ce genre d'erreurs dans Visual Studio :

    error C2871: 'cv' : a namespace with this name does not exist

    Merci

  2. #2
    Membre émérite
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    2 764
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 2 764
    Points : 2 705
    Points
    2 705
    Par défaut
    Faudrait que tu mettes la ligne de code sur laquelle pointe l'erreur.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 41
    Points : 8
    Points
    8
    Par défaut
    C'est la ligne juste après les includes


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    #include <cv.h>
    #include <highgui.h>
    #include <math.h>
    #include "stdafx.h"
     
    using namespace cv;
     
    int main(int argc, char** argv)
    {
        Mat img, gray;
        if( argc != 2 && !(img=imread(argv[1], 1)).data)
            return -1;
        cvtColor(img, gray, CV_BGR2GRAY);
        // smooth it, otherwise a lot of false circles may be detected
        GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
        vector<Vec3f> circles;
        HoughCircles(gray, circles, CV_HOUGH_GRADIENT,
                     2, gray->rows/4, 200, 100 );
        for( size_t i = 0; i < circles.size(); i++ )
        {
             Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
             int radius = cvRound(circles[i][2]);
             // draw the circle center
             circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
             // draw the circle outline
             circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
        }
        namedWindow( "circles", 1 );
        imshow( "circles", img );
        return 0;
    }

  4. #4
    Membre émérite
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    2 764
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 2 764
    Points : 2 705
    Points
    2 705
    Par défaut
    Je suppose que l'espace de nom cv n'est défini dans aucun des .h...

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 41
    Points : 8
    Points
    8
    Par défaut
    Et voilà le rapport d'erreur


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    1>------ Rebuild All started: Project: hough, Configuration: Release Win32 ------
    1>Build started 11.07.2012 17:09:55.
    1>_PrepareForClean:
    1>  Deleting file "Release\hough.lastbuildstate".
    1>InitializeBuildStatus:
    1>  Touching "Release\hough.unsuccessfulbuild".
    1>ClCompile:
    1>  stdafx.cpp
    1>d:\entwicklung\opencv\opencv-2.4.0\opencv\modules\flann\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1>          C:\Programme\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) : see declaration of 'fopen'
    1>  hough.cpp
    1>hough.cpp(1): warning C4627: '#include <cv.h>': skipped when looking for precompiled header use
    1>          Add directive to 'StdAfx.h' or rebuild precompiled header
    1>hough.cpp(2): warning C4627: '#include <highgui.h>': skipped when looking for precompiled header use
    1>          Add directive to 'StdAfx.h' or rebuild precompiled header
    1>hough.cpp(3): warning C4627: '#include <math.h>': skipped when looking for precompiled header use
    1>          Add directive to 'StdAfx.h' or rebuild precompiled header
    1>hough.cpp(6): error C2871: 'cv' : a namespace with this name does not exist
    1>hough.cpp(10): error C2065: 'Mat' : undeclared identifier
    1>hough.cpp(10): error C2146: syntax error : missing ';' before identifier 'img'
    1>hough.cpp(10): error C2065: 'img' : undeclared identifier
    1>hough.cpp(10): error C2065: 'gray' : undeclared identifier
    1>hough.cpp(11): error C2065: 'img' : undeclared identifier
    1>hough.cpp(11): error C2228: left of '.data' must have class/struct/union
    1>hough.cpp(11): error C3861: 'imread': identifier not found
    1>hough.cpp(13): error C2065: 'img' : undeclared identifier
    1>hough.cpp(13): error C2065: 'gray' : undeclared identifier
    1>hough.cpp(13): error C2065: 'CV_BGR2GRAY' : undeclared identifier
    1>hough.cpp(13): error C3861: 'cvtColor': identifier not found
    1>hough.cpp(15): error C2065: 'gray' : undeclared identifier
    1>hough.cpp(15): error C2065: 'gray' : undeclared identifier
    1>hough.cpp(15): error C3861: 'GaussianBlur': identifier not found
    1>hough.cpp(15): error C3861: 'Size': identifier not found
    1>hough.cpp(16): error C2065: 'vector' : undeclared identifier
    1>hough.cpp(16): error C2065: 'Vec3f' : undeclared identifier
    1>hough.cpp(16): error C2065: 'circles' : undeclared identifier
    1>hough.cpp(17): error C2065: 'gray' : undeclared identifier
    1>hough.cpp(17): error C2065: 'circles' : undeclared identifier
    1>hough.cpp(17): error C2065: 'CV_HOUGH_GRADIENT' : undeclared identifier
    1>hough.cpp(18): error C2065: 'gray' : undeclared identifier
    1>hough.cpp(18): error C2227: left of '->rows' must point to class/struct/union/generic type
    1>          type is ''unknown-type''
    1>hough.cpp(17): error C3861: 'HoughCircles': identifier not found
    1>hough.cpp(19): error C2065: 'circles' : undeclared identifier
    1>hough.cpp(19): error C2228: left of '.size' must have class/struct/union
    1>          type is ''unknown-type''
    1>hough.cpp(21): error C2065: 'Point' : undeclared identifier
    1>hough.cpp(21): error C2146: syntax error : missing ';' before identifier 'center'
    1>hough.cpp(21): error C2065: 'circles' : undeclared identifier
    1>hough.cpp(21): error C2065: 'circles' : undeclared identifier
    1>hough.cpp(21): error C3861: 'center': identifier not found
    1>hough.cpp(21): error C3861: 'cvRound': identifier not found
    1>hough.cpp(21): error C3861: 'cvRound': identifier not found
    1>hough.cpp(22): error C2065: 'circles' : undeclared identifier
    1>hough.cpp(22): error C3861: 'cvRound': identifier not found
    1>hough.cpp(24): error C2065: 'img' : undeclared identifier
    1>hough.cpp(24): error C2065: 'center' : undeclared identifier
    1>hough.cpp(24): error C3861: 'circle': identifier not found
    1>hough.cpp(24): error C3861: 'Scalar': identifier not found
    1>hough.cpp(26): error C2065: 'img' : undeclared identifier
    1>hough.cpp(26): error C2065: 'center' : undeclared identifier
    1>hough.cpp(26): error C3861: 'circle': identifier not found
    1>hough.cpp(26): error C3861: 'Scalar': identifier not found
    1>hough.cpp(28): error C3861: 'namedWindow': identifier not found
    1>hough.cpp(29): error C2065: 'img' : undeclared identifier
    1>hough.cpp(29): error C3861: 'imshow': identifier not found
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:01.95
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

  6. #6
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 41
    Points : 8
    Points
    8
    Par défaut
    Et donc comment est il possible de le definir?

  7. #7
    Membre émérite
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    2 764
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 2 764
    Points : 2 705
    Points
    2 705
    Par défaut
    Commence par déplacer la ligne

    avant toute autre directive d'inclusion.

  8. #8
    Membre émérite

    Inscrit en
    Mai 2008
    Messages
    1 014
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 1 014
    Points : 2 252
    Points
    2 252
    Par défaut
    C'est un problème de header précompilé.
    Lorsque les headers précompilés sont activés, sous Visual Studio, tous les fichiers .cpp doivent obligatoirement commencer par #include "stdafx.h". Toutes les lignes précédant #include "stdafx.h" sont purement et simplement ignorées, donc par exemple ici #include <cv.h> etc.


    C'est ce que dit le message d'erreur :

    '#include <cv.h>': skipped when looking for precompiled header use
    1> Add directive to 'StdAfx.h' or rebuild precompiled header

  9. #9
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 41
    Points : 8
    Points
    8
    Par défaut
    La déplacer comment ca??? je ne comprends pas?? elle n'est pas au bon endroit?

  10. #10
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 41
    Points : 8
    Points
    8
    Par défaut
    ok donc comme ca

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    #include "stdafx.h"
    #include <cv.h>
    #include <highgui.h>
    #include <math.h>
     
    using namespace cv;
    donc là d'après le debug ce problème semble résolu :

    1>------ Rebuild All started: Project: hough, Configuration: Release Win32 ------
    1>Build started 11.07.2012 17:58:15.
    1>_PrepareForClean:
    1> Deleting file "Release\hough.lastbuildstate".
    1>InitializeBuildStatus:
    1> Touching "Release\hough.unsuccessfulbuild".
    1>ClCompile:
    1> stdafx.cpp
    1>d:\entwicklung\opencv\opencv-2.4.0\opencv\modules\flann\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1> C:\Programme\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) : see declaration of 'fopen'
    1> hough.cpp
    1>d:\entwicklung\opencv\opencv-2.4.0\opencv\modules\flann\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1> C:\Programme\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) : see declaration of 'fopen'
    1>hough.cpp(19): error C2819: type 'cv::Mat' does not have an overloaded member 'operator ->'
    1> D:\Entwicklung\OpenCV\OpenCV-2.4.0\opencv\modules\core\include\opencv2/core/core.hpp(1628) : see declaration of 'cv::Mat'
    1> did you intend to use '.' instead?
    1>hough.cpp(19): error C2232: '->cv::Mat::rows' : left operand has 'class' type, use '.'
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:03.64
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 17/03/2009, 11h36
  2. Problème avec la lib lti et visual studio 2005
    Par pasqual dans le forum Visual C++
    Réponses: 3
    Dernier message: 25/11/2008, 16h31
  3. Problème avec l'importation de projet Visual Studio 2005
    Par masterofsword0132 dans le forum Dreamshield
    Réponses: 5
    Dernier message: 26/08/2008, 17h00
  4. Réponses: 3
    Dernier message: 04/08/2008, 08h01
  5. Réponses: 1
    Dernier message: 17/07/2006, 17h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo