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
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
Faudrait que tu mettes la ligne de code sur laquelle pointe l'erreur.
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; }
Je suppose que l'espace de nom cv n'est défini dans aucun des .h...
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 ==========
Et donc comment est il possible de le definir?
Commence par déplacer la ligne
avant toute autre directive d'inclusion.
Code : Sélectionner tout - Visualiser dans une fenêtre à part #include "stdafx.h"
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
Partager