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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
#include "stdafx.h" #include <iostream> #include <iomanip> #include <cstring> using namespace std; int getIntZodiak(char * str); // прототип функции, которая возвращает порядковый номер знака зодиака struct Znak { char name[50]; // фамилия, имя char zodiac[20]; // знак зодиака int bday[3]; // дата рождения дд.мм.гг }; // массив указателей на строки (знаки зодиака) const char *sign_zodiac[12] = {"Овен", "Телец", "Близнецы", "Рак" , "Лев", "Дева", "Весы", "Скорпион", "Стрелец", "Козерог", "Водолей", "Рыбы" }; // порядок следования знаков зодиака int main() { const int size_array = 8; // количество записей Znak book[size_array]; // объявляем массив структур int counter_rec = 0; // счётчик записей while (counter_rec < size_array) // пока не внесено 8 записей { cout << "Введите имя и фамилию через пробел: "; cin.getline(book[counter_rec].name, 50); cout << "Введите знак зодиака: "; cin.getline(book[counter_rec].zodiac, 20); cout << "Введите дату рождения в формате (дд.мм.гг) "; cin >> setw(2) >> (book[counter_rec].bday[0]); // считать первые два символа, т.е. день cin.ignore(); // пропустить символ точки cin >> setw(2) >> book[counter_rec].bday[1]; // считать следующие два символа, т.е. месяц cin.ignore(); // пропустить символ точки cin >> setw(4) >> book[counter_rec].bday[2]; // считать четыре символа, т.е. год cin.get(); // считываем символ новой строки 'n' counter_rec++; // инкремент счётчика записей } // сортировка записей в массиве структур for (int ctr1 = 0; ctr1 < size_array; ctr1++) { for (int ctr2 = ctr1 + 1; ctr2 < size_array; ctr2++) { if (getIntZodiak(book[ctr1].zodiac) > getIntZodiak(book[ctr2].zodiac)) // если порядок не правильный, то поменять местами записи { char temp_name[50]; // временная переменная для перестановки строк: имя и знак зодиака // перестановка имён strcpy(temp_name, book[ctr1].name); strcpy(book[ctr1].name, book[ctr2].name); strcpy(book[ctr2].name, temp_name); // перестановка знака зодиака strcpy(temp_name, book[ctr1].zodiac); strcpy(book[ctr1].zodiac, book[ctr2].zodiac); strcpy(book[ctr2].zodiac, temp_name); int temp_data[3] = {book[ctr1].bday[0], book[ctr1].bday[1], book[ctr1].bday[2]}; // временный массив, для обмена д.р. // перестановка дат рождения book[ctr1].bday[0] = book[ctr2].bday[0]; book[ctr1].bday[1] = book[ctr2].bday[1]; book[ctr1].bday[2] = book[ctr2].bday[2]; book[ctr2].bday[0] = temp_data[0]; book[ctr2].bday[1] = temp_data[1]; book[ctr2].bday[2] = temp_data[2]; } } } int month = 0; cout << "Введите порядковый номер месяца: "; cin >> month; if (month < 1 || month > 12) { cout << "Месяц указан не корректно!" << endl; //return -1; } else { // печать записей, месяц которых совпадает с введённым cout << endl; bool no_records = false; // переменная-флаг, отвечающая за существование записей, месяц которых равен введённому for (int counter = 0; counter < size_array; counter++) { if (book[counter].bday[1] == month) // если совпадает номер месяца в записи с введённым с клавиатуры { no_records = true; cout << book[counter].name << endl; // имя и фамилия cout << book[counter].zodiac << endl; // знак зодиака cout << setfill('0') << setw(2) << book[counter].bday[0] << "." << setw(2) << book[counter].bday[1] << "." << setw(2) << book[counter].bday[2] << endl << endl; // дата рождения } } if (no_records) cout << "Нет людей родившихся " << month << " месяца." << endl; } return 0; } int getIntZodiak(char * str) // функция возвращает порядковый номер знака зодиака { for (int counter = 0; counter < 12; counter++) { if (!strcmp(str,sign_zodiac[counter])) // если знаки зодиака совпадают, то вернуть порядковый номер return counter; } return -1; // возвращаемое значение, в случае, если имя передоваемое как параметр не совпало ни с одним знаком зодиака } |
I am new to visual studio.I have created a simple console application and then selected an empty project of c++.Then pasted the following code
#include "stdafx.h"
#include <cstdio>
#include <iostream>
#include <fstream>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <vector>
#include "GL/glut.h"
#include "GL/glu.h"
#include "GL/gl.h"
#include <math.h>
#include <time.h>
using namespace std;
using namespace cv;
const float zNear = 0.05;
const float zFar = 500.0;
int width, height;
int draw = 0;
Point FIX_X(0, 0), FIX_Y(0, 0), FIX_Z(0, 0);
float skew_x, skew_y, skew_z;
VideoCapture cap(0);
Mat tmp, test;
Mat intrinsic_Matrix(3, 3, CV_64F);
Mat distortion_coeffs(8, 1, CV_64F);
Mat Projection(4, 4, CV_64FC1);
double largest_area;
int largest_contour_index;
int n = 0;
int no_of_fingers = 0;
vector<vector<pair<float, Point>>> position;
vector<int> finger_count;
Point first, second, third;
float size_of_pot = 10;
int rot_angle = 10;
float distanceP2P(Point a, Point b) {
float d = sqrt(fabs(pow(a.x - b.x, 2) + pow(a.y - b.y, 2)));
return d;
}
float getAngle(Point s, Point f, Point e) {
float l1 = distanceP2P(f, s);
float l2 = distanceP2P(f, e);
float dot = (s.x - f.x)*(e.x - f.x) + (s.y - f.y)*(e.y - f.y);
float angle = acos(dot / (l1*l2));
angle = angle * 180 / 3.147;
return angle;
}
String intToString(int number) {
stringstream ss;
ss << number;
string str = ss.str();
return str;
}
bool pairCompare(const pair<float, Point>&i, const pair<float, Point>&j) {
return i.first <j.first;
}
GLfloat* convertMatrixType(const cv::Mat& m)
{
typedef double precision;
Size s = m.size();
GLfloat* mGL = new GLfloat[s.width*s.height];
for (int ix = 0; ix < s.width; ix++)
{
for (int iy = 0; iy < s.height; iy++)
{
mGL[ix*s.height + iy] = m.at<precision>(iy, ix);
}
}
return mGL;
}
void generateProjectionModelview(const cv::Mat& calibration, const cv::Mat& rotation, const cv::Mat& translation, cv::Mat& projection, cv::Mat& modelview)
{
typedef double precision;
projection.at<precision>(0, 0) = 2 * calibration.at<precision>(0, 0) / width;
projection.at<precision>(1, 0) = 0;
projection.at<precision>(2, 0) = 0;
projection.at<precision>(3, 0) = 0;
projection.at<precision>(0, 1) = 0;
projection.at<precision>(1, 1) = 2 * calibration.at<precision>(1, 1) / height;
projection.at<precision>(2, 1) = 0;
projection.at<precision>(3, 1) = 0;
projection.at<precision>(0, 2) = 1 - 2 * calibration.at<precision>(0, 2) / width;
projection.at<precision>(1, 2) = -1 + (2 * calibration.at<precision>(1, 2) + 2) / height;
projection.at<precision>(2, 2) = (zNear + zFar) / (zNear - zFar);
projection.at<precision>(3, 2) = -1;
projection.at<precision>(0, 3) = 0;
projection.at<precision>(1, 3) = 0;
projection.at<precision>(2, 3) = 2 * zNear*zFar / (zNear - zFar);
projection.at<precision>(3, 3) = 0;
modelview.at<precision>(0, 0) = rotation.at<precision>(0, 0);
modelview.at<precision>(1, 0) = rotation.at<precision>(1, 0);
modelview.at<precision>(2, 0) = rotation.at<precision>(2, 0);
modelview.at<precision>(3, 0) = 0;
modelview.at<precision>(0, 1) = rotation.at<precision>(0, 1);
modelview.at<precision>(1, 1) = rotation.at<precision>(1, 1);
modelview.at<precision>(2, 1) = rotation.at<precision>(2, 1);
modelview.at<precision>(3, 1) = 0;
modelview.at<precision>(0, 2) = rotation.at<precision>(0, 2);
modelview.at<precision>(1, 2) = rotation.at<precision>(1, 2);
modelview.at<precision>(2, 2) = rotation.at<precision>(2, 2);
modelview.at<precision>(3, 2) = 0;
modelview.at<precision>(0, 3) = translation.at<precision>(0, 0);
modelview.at<precision>(1, 3) = translation.at<precision>(1, 0);
modelview.at<precision>(2, 3) = translation.at<precision>(2, 0);
modelview.at<precision>(3, 3) = 1;
// This matrix corresponds to the change of coordinate systems.
static double changeCoordArray[4][4] = { { 1, 0, 0, 0 },{ 0, -1, 0, 0 },{ 0, 0, -1, 0 },{ 0, 0, 0, 1 } };
static Mat changeCoord(4, 4, CV_64FC1, changeCoordArray);
modelview = changeCoord*modelview;
}
void calibrate(Mat &intrinsic_Matrix, Mat &distortion_coeffs)
{
vector< vector< Point2f> > AllimagePoints;
vector< vector< Point3f> > AllobjectPoints;
char str[100];
stringstream st;
int no_of_images = 1;
Size imagesize;
Mat gray;
while (no_of_images <= 14)
{
st << "E:/SelectedImages/Selected" << ++no_of_images << ".jpg";
String strcopy3 = st.str();
st.str("");
Mat img = imread(strcopy3, 1);
if (!img.data)
break;
imagesize = Size(img.rows, img.cols);
cvtColor(img, gray, CV_RGB2GRAY);
vector< Point2f> corners;
bool sCorner = false;
sCorner = findChessboardCorners(gray, Size(7, 7), corners);
if (sCorner)
{
cornerSubPix(gray, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
drawChessboardCorners(img, Size(7, 7), corners, sCorner);
if (corners.size() == 7 * 7)
{
vector< Point2f> v_tImgPT;
vector< Point3f> v_tObjPT;
for (int j = 0; j< corners.size(); ++j)
{
Point2f tImgPT;
Point3f tObjPT;
tImgPT.x = corners[j].x;
tImgPT.y = corners[j].y;
tObjPT.x = j % 7 * 3;
tObjPT.y = j / 7 * 3;
tObjPT.z = 0;
v_tImgPT.push_back(tImgPT);
v_tObjPT.push_back(tObjPT);
}
AllimagePoints.push_back(v_tImgPT);
AllobjectPoints.push_back(v_tObjPT);
}
}
st << "E:/DetectedImages/Detected" << no_of_images + 1 << ".jpg";
String strcopy1 = st.str();
st.str("");
imwrite(strcopy1, img);
//imshow("pattern",img);
//cvWaitKey(30);
}
vector< Mat> rvecs, tvecs;
if (AllimagePoints.size()>0)
{
calibrateCamera(AllobjectPoints, AllimagePoints, imagesize, intrinsic_Matrix, distortion_coeffs, rvecs, tvecs);
}
}
void renderBackgroundGL(const cv::Mat& image)
{
GLint polygonMode[2];
glGetIntegerv(GL_POLYGON_MODE, polygonMode);
glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);
glLoadIdentity();
gluOrtho2D(0.0, 1.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
static bool textureGenerated = false;
static GLuint textureId;
if (!textureGenerated)
{
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
textureGenerated = true;
}
// Copy the image to the texture.
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.size().width, image.size().height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image.data);
// Draw the image.
glEnable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLES);
glNormal3f(0.0, 0.0, 1.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(0.0, 0.0, 0.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(1.0, 0.0, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(1.0, 0.0, 0.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(1.0, 0.0);
glVertex3f(1.0, 1.0, 0.0);
glEnd();
glDisable(GL_TEXTURE_2D);
// Clear the depth buffer so the texture forms the background.
glClear(GL_DEPTH_BUFFER_BIT);
// Restore the polygon mode state.
glPolygonMode(GL_FRONT, polygonMode[0]);
glPolygonMode(GL_BACK, polygonMode[1]);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
namedWindow("live", 1);
Mat gray1, test, modelview, dis_img, thresh, img1;
Mat rvec(3, 1, DataType<double>::type);
Mat tvec(3, 1, DataType<double>::type);
modelview.create(4, 4, CV_64FC1);
//Projection.create(4, 4, CV_64FC1);
vector< Point2f> corners1;
vector< Point2f> imagePoints1;
vector< Point3f> objectPoints1;
largest_area = 0;
largest_contour_index = 0;
clock_t clock_1 = clock();
cap >> dis_img;
//resize(dis_img,dis_img,Size(180,180),0,0);
if (!dis_img.data)
{
exit(3);
}
img1 = dis_img.clone();
dis_img.copyTo(img1);
//resize(img1,img1,Size(180,180),0,0);
cvtColor(dis_img, dis_img, COLOR_BGR2YCrCb);
inRange(dis_img, Scalar(0, 133, 77), Scalar(255, 173, 127), thresh);
clock_t clock_2 = clock();
cout << "threshold(Skin Color Segmentation) time is :" << (double)(clock_2 - clock_1) << endl;
dilate(thresh, thresh, Mat());
blur(thresh, thresh, Size(5, 5), Point(-1, -1), BORDER_DEFAULT);
vector<vector<Point>> contours;
vector<Point> FingerTips;
vector<Vec4i> hierachy;
vector<Vec4i> defects;
vector<Point> defect_circle;
vector<vector<Point>> hull(1);
Point2f center;
float radius;
clock_t clock_3 = clock();
cout << "image filtering (smoothing) time is :" << (double)(clock_3 - clock_2) << endl;
findContours(thresh, contours, hierachy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
//cout<<"contour"<<endl;
int cont_size = contours.size();
for (int i = 0; i<cont_size; i++)
{
double a = contourArea(contours[i], false);
if (a>largest_area)
{
largest_area = a;
largest_contour_index = i;
}
}
vector<int> hull_index;
Rect brect;
if (largest_area>0 && contours[largest_contour_index].size()>5)
{
approxPolyDP(contours[largest_contour_index], contours[largest_contour_index], 8, true);
//cout<<"approx_poly"<<endl;
convexHull(Mat(contours[largest_contour_index]), hull[0], false, true);
// cout<<"convex_hull"<<endl;
brect = boundingRect(contours[largest_contour_index]);
//cout<<"bounding_rect"<<endl;
convexHull(Mat(contours[largest_contour_index]), hull_index, true);
//cout<<"convex_hull2"<<endl;
convexityDefects(contours[largest_contour_index], hull_index, defects);
//cout<<"convexity defect"<<endl;
// Mom ents mom=moments(contours[largest_contour_index]);
// draw mass center
// circle(img,Point(mom.m10/mom.m00,mom.m01/mom.m00),2,cv::Scalar(0),2);
Scalar colorw = Scalar(0, 255, 0);
Scalar color1 = Scalar(0, 0, 255);
//drawContours(img,contours,largest_contour_index,color,2, 8, hierachy);
//drawContours(timg,contours,largest_contour_index,color,1, 8, hierachy);
//drawContours(timg, hull, 0, color1, 1, 8, vector<Vec4i>(), 0, Point() );
// drawContours(img, hull, 0, color1, 2, 8, vector<Vec4i>(), 0, Point() );
int defc_size = defects.size();
Point ptStart;
Point ptEnd;
Point ptStart2;
Point ptEnd2;
Point ptFar;
int count = 1;
int startidx2;
int endidx2;
int tolerance = brect.height / 5;
float angleTol = 95;
for (int in = 0; in<defc_size; in++)
{
//Vec4i& v=(*d); d++;
int startidx = defects[in].val[0]; ptStart = contours[largest_contour_index].at(startidx);
int endidx = defects[in].val[1]; ptEnd = contours[largest_contour_index].at(endidx);
int faridx = defects[in].val[2]; ptFar = contours[largest_contour_index].at(faridx);
if (in + 1<defc_size)
startidx2 = defects[in + 1].val[0]; ptStart = contours[largest_contour_index].at(startidx);
endidx2 = defects[in + 1].val[1]; ptEnd = contours[largest_contour_index].at(endidx);
if (distanceP2P(ptStart, ptFar) > tolerance && distanceP2P(ptEnd, ptFar) > tolerance && getAngle(ptStart, ptFar, ptEnd) < angleTol) {
{
if (in + 1<defc_size)
{
if (distanceP2P(ptStart, ptEnd2) < tolerance)
contours[largest_contour_index][startidx] = ptEnd2;
else {
if (distanceP2P(ptEnd, ptStart2) < tolerance)
contours[largest_contour_index][startidx2] = ptEnd;
}
}
defect_circle.push_back(ptFar);
// cout<<"ptfar"<<ptFar.x<<"&&"<<ptFar.y<<endl;
if (count == 1)
{
FingerTips.push_back(ptStart);
cv::circle(img1, ptStart, 2, Scalar(0, 255, 0), 2);
putText(img1, intToString(count), ptStart - Point(0, 30), FONT_HERSHEY_PLAIN, 1.2f, Scalar(255, 0, 0), 2);
}
FingerTips.push_back(ptEnd);
count++;
putText(img1, intToString(count), ptEnd - Point(0, 30), FONT_HERSHEY_PLAIN, 1.2f, Scalar(255, 0, 0), 2);
cv::circle(img1, ptEnd, 2, Scalar(0, 255, 0), 2);
//cv::circle( img, ptFar, 2, Scalar(255,255,255 ), 2 );
}
}
}
// circle(img, ptStart,2,Scalar(0xFF,0x60,0x02 ), 2, 8, 0 );
//cv::circle( img, ptEnd, 4, Scalar( 0xFF,0x60,0x02 ), 2 );
clock_t clock_4 = clock();
cout << "fingerTip detection time is :" << (double)(clock_4 - clock_3) << endl;
// cout<<"hii"<<endl;
bool two_fn = false;
bool five_fn = false;
if (defect_circle.size() == 1)
{
two_fn = true;
Point fn = FingerTips.back();
FingerTips.pop_back();
Point ln = FingerTips.back();
FingerTips.pop_back();
Point defect_point = defect_circle.back();
float curr = getAngle(fn, defect_point, ln);
curr = curr / 10;
curr = 10 - curr;
renderBackgroundGL(img1);
objectPoints1.push_back(Point3d(9, 6, 0));
imagePoints1.push_back(defect_point);
objectPoints1.push_back(Point3d(9, 6, 0));
imagePoints1.push_back(defect_point);
objectPoints1.push_back(Point3d(19, 6, 0));
imagePoints1.push_back(fn);
objectPoints1.push_back(Point3d(9, 18, 0));
imagePoints1.push_back(ln);
// cout<<width<<" &"<<height<<endl;
// cout<<"solvepnp"<<endl;
solvePnP(Mat(objectPoints1), Mat(imagePoints1), intrinsic_Matrix, distortion_coeffs, rvec, tvec);
cv::Mat rotation;
cv::Rodrigues(rvec, rotation);
double offsetA[3][1] = { 9,6,6 };
Mat offset(3, 1, CV_64FC1, offsetA);
tvec = tvec + rotation*offset;
generateProjectionModelview(intrinsic_Matrix, rotation, tvec, Projection, modelview);
glMatrixMode(GL_PROJECTION);
GLfloat* projection = convertMatrixType(Projection);
glLoadMatrixf(projection);
delete[] projection;
glMatrixMode(GL_MODELVIEW);
GLfloat* modelView = convertMatrixType(modelview);
glLoadMatrixf(modelView);
delete[] modelView;
//glTranslatef(0.0f,0.0f,-5.0f);
glPushMatrix();
glColor3f(1.0, 0.0, 0.0);
glutWireTeapot(10.0 / curr);
glPopMatrix();
glColor3f(1.0, 1.0, 1.0);
}
//Rotation Module
if (defect_circle.size() == 4)
{
five_fn = true;
minEnclosingCircle(defect_circle, center, radius);
//circle(img, center, (int)radius,Scalar(255,255,255), 2, 8, 0 );
circle(img1, center, 2, Scalar(0), 2, 8, 0);
vector<pair<float, Point>> pos;
for (int in = 0; in<FingerTips.size(); in++)
{
Point p = FingerTips.back();
FingerTips.pop_back();
//if(in==0)
//{
pos.push_back(make_pair(distanceP2P(center, p), p));
//position.push_back(pos);
}
// }
//else
// {
// cout<<"size is"<<position.size()<<endl;
// position[n].push_back(make_pair(distanceP2P(center,p),p));
//}
sort(pos.begin(), pos.end(), pairCompare);
// vector<pair<float,Point>> now=position[i].back();
first = pos.back().second;
pos.pop_back();
//cout<<"new value :"<<new1.x<<" && "<<new1.y<<endl;
second = pos.back().second;
pos.pop_back();
third = pos.back().second;
pos.pop_back();
if (third.y<second.y&&second.y<first.y)
{
// cout<<"vertical pose"<<endl;
FIX_X.x = center.x + 40;
FIX_X.y = center.y;
FIX_Y.x = center.x;
FIX_Y.y = center.y - 40;
}
skew_x = getAngle(first, center, FIX_X);
skew_y = getAngle(third, center, FIX_Y);
cout << skew_x << "&" << skew_y << endl;
if (first.x<img1.cols)
line(img1, center, first, Scalar(200, 200, 200), 2, 8, 0);
line(img1, center, FIX_X, Scalar(200, 200, 200), 2, 8, 0);
if (second.x<img1.cols)
line(img1, center, second, Scalar(0, 255, 0), 2, 8, 0);
if (third.x<img1.cols)
line(img1, center, third, Scalar(0, 0, 255), 2, 8, 0);
line(img1, center, FIX_Y, Scalar(0, 0, 255), 2, 8, 0);
// line(img1,center,first,Scalar(255,255,255),2,8,0);
// line(img1,center,second,Scalar(0,255,255),2,8,0);
// line(img1,center,third,Scalar(0,0,255),2,8,0);
renderBackgroundGL(img1);
/* cvtColor(test, gray1, CV_RGB2GRAY);
bool sCorner1=findChessboardCorners(gray1, Size(7, 7), corners1);
imshow("live",test);
if(sCorner1)
{
cornerSubPix(gray1, corners1, Size(11,11), Size(-1,-1), TermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1));
if(corners1.size() == 7*7)
{control pan
for(int j=0; j< corners1.size(); ++j)
{
Point2f tImgPT;
Point3f tObjPT;
tImgPT.x = corners1[j].x;
tImgPT.y = corners1[j].y;
tObjPT.x = j%7*3;
tObjPT.y = j/7*3;
tObjPT.z = 0;
imagePoints1.push_back(tImgPT);
objectPoints1.push_back(tObjPT);
}
vector<Point2f> projectedPoints;
vector<Point3f> axis;
axis.push_back(Point3f(6,0,0));
axis.push_back(Point3f(0,6,0));
axis.push_back(Point3f(0,0,6)); */
objectPoints1.push_back(Point3d(9, 6, 0));
imagePoints1.push_back(center);
objectPoints1.push_back(Point3d(9, 18, 0));
imagePoints1.push_back(first);
objectPoints1.push_back(Point3d(19, 6, 0));
imagePoints1.push_back(third);
objectPoints1.push_back(Point3d(15, 15, 0));
imagePoints1.push_back(second);
// cout<<width<<" &"<<height<<endl;
// cout<<"solvepnp"<<endl;
solvePnP(Mat(objectPoints1), Mat(imagePoints1), intrinsic_Matrix, distortion_coeffs, rvec, tvec);
cv::Mat rotation;
cv::Rodrigues(rvec, rotation);
double offsetA[3][1] = { 9,6,0 };
Mat offset(3, 1, CV_64FC1, offsetA);
tvec = tvec + rotation*offset;
generateProjectionModelview(intrinsic_Matrix, rotation, tvec, Projection, modelview);
/* double offsetA[3][1] = {{(7-1.0)/2.0}, {(7-1.0)/2.0}, {0}};
Mat offset(3, 1, CV_64FC1, offsetA);
tvec = tvec + rotation*offset;
for(unsigned int row=0; row<3; ++row)
{
for(unsigned int col=0; col<3; ++col)
{
modelview.at<float>(row, col) = rotation.at<float>(row, col);
cout<<modelview.at<float>(row,col)<<endl;
}
modelview.at<float>(row, 3) = tvec.at<float>(row, 0);
}
modelview.at<float>(3, 3) = 1.0f;
cout<<endl;
static float changeCoordArray[4][4] = {{-1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 1}};
static Mat changeCoord(4, 4, CV_64FC1, changeCoordArray);
modelview = changeCoord*modelview;
cv::Mat glmodelview = cv::Mat::zeros(4, 4, CV_64F);
transpose(modelview , glmodelview);
gluLookAt(0.0,2.0,-50.0,0.0,0.5,0.0,0.0,1.0,0.0);
/* glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float fx=intrinsic_Matrix.at<float>(0,0);
float fy=intrinsic_Matrix.at<float>(1,1);
float cf=(2*atanf(0.5*height/fy)*180/3.14);
float aspect=(width*fy)/(height*fx);
//gluPerspective(cf,1.0, zNear, zFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLoadMatrixf(&glmodelview.at<float>(0,0)); */
glMatrixMode(GL_PROJECTION);
GLfloat* projection = convertMatrixType(Projection);
glLoadMatrixf(projection);
delete[] projection;
glMatrixMode(GL_MODELVIEW);
GLfloat* modelView = convertMatrixType(modelview);
glLoadMatrixf(modelView);
delete[] modelView;
//glTranslat ef(0.0f,0.0f,-5.0f);
glPushMatrix();
glColor3f(1.0, 0.0, 0.0);
glRotatef(skew_x, 1.0, 0.0, 0.0);
glRotatef(skew_y, 0.0, 1.0, 0.0);
glutWireTeapot(10.0);
glPopMatrix();
glColor3f(1.0, 1.0, 1.0);
clock_t clock_5 = clock();
cout << "interaction time is :" << (double)(clock_5 - clock_4) << endl;
}
imshow("live", img1);
cout << "----------------------------------------------" << endl;
glFlush();
glutSwapBuffers();
}
waitKey(27);
glutPostRedisplay();
}
void reshape(int x, int y)
{
width = x; height = y;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/*Projection.at<float>(0,0) = 2*intrinsic_Matrix.at<float>(0,0)/width;
Projection.at<float>(1,0) = 0;
Projection.at<float>(2,0) = 0;
Projection.at<float>(3,0) = 0;
Projection.at<float>(0,1) = 0;
Projection.at<float>(1,1) = 2*intrinsic_Matrix.at<float>(1,1)/height;
Projection.at<float>(2,1) = 0;
Projection.at<float>(3,1) = 0;
Projection.at<float>(0,2) = 1-2*intrinsic_Matrix.at<float>(0,2)/width;
Projection.at<float>(1,2) = -1+(2*intrinsic_Matrix.at<float>(1,2)+2)/height;
Projection.at<float>(2,2) = (zNear+zFar)/(zNear - zFar);
Projection.at<float>(3,2) = -1;
Projection.at<float>(0,3) = 0;
Projection.at<float>(1,3) = 0;
Projection.at<float>(2,3) = 2*zNear*zFar/(zNear - zFar);
Projection.at<float>(3,3) = 0;
cv::Mat projection = cv::Mat::zeros(4, 4, CV_64F);
transpose(Projection ,projection);
glLoadMatrixf(&projection.at<float>(0,0)); */
// gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0);
/* float fx=intrinsic_Matrix.at<float>(0,0);
float fy=intrinsic_Matrix.at<float>(1,1);
float cf=(2*atanf(0.5*height/fy)*180/3.14);
cout<<fx<<" "<<fy<<endl;
float aspect=(width*fy)/(height*fx); */
//gluPerspective(cf,CALIB_FIX_ASPECT_RATIO, zNear, zFar);
//glMatrixMode(GL_MODELVIEW);
// gluPerspective(60,width/height, zNear, zFar);
//glOrtho(-100,100,-100.0,100,zNear, zFar);
}
void init()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void main()
{
if (!cap.isOpened())
{
exit(-1);
}
cap >> test;
if (!test.data)
{
exit(-1);
}
// resize(test,test,Size(180,180),0,0);
width = test.cols;
height = test.rows;
cout << width << endl;
calibrate(intrinsic_Matrix, distortion_coeffs);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutCreateWindow("code4change");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}
But when i compile the cide it always get error message «Cannot open include file: ‘stdafx.h'».What should i do?.As i know stdafx.h is a c++ headerfile.
please help me….
me all the time that error occurs, look after the forums but not found out what this is about
this is code:
#include «stdafx.h»
#include <iostream>
/*
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include «randomcard.h»
*/
# define CLANOVI_OBITELJI 100
# define MJESECI 100
using namespace std;
int main(){
float dzeparci[CLANOVI_OBITELJI][MJESECI];
float dzeparci_po_clanu[CLANOVI_OBITELJI];
float dzeparci_po_mjesecu[MJESECI];
int br_clanova,br_mjeseci;
cout<<«Unesi broj clanova obitlji: «;
cin>>br_clanova;
cout<<«Unesi broj mjeseci: «;
cin>>br_mjeseci;
for(int i=0; i<br_clanova; i++){
cout<<«n»<<i+1<<«. CLAN OBITELJI»<<endl;
for(int j=0; j<br_mjeseci; j++){
cout<<j+1<<«. mjesec: «;
cin>>dzeparci[i][j];
}
}
float zbroj_dzeparca=0;
for(int i=0; i<br_clanova; i++){
zbroj_dzeparca=0;
for(int j=0; j<br_mjeseci; j++){
zbroj_dzeparca += dzeparci[i][j];
}
dzeparci_po_clanu[i] = zbroj_dzeparca/br_mjeseci;
}
for(int i=0; i<br_mjeseci; i++){
zbroj_dzeparca=0;
for(int j=0; j<br_clanova; j++){
zbroj_dzeparca += dzeparci[j][i];
}
dzeparci_po_mjesecu[i] = zbroj_dzeparca/br_clanova;
}
cout<<«DZEPARCI»<<endl;
for(int i=0; i<br_clanova; i++){
cout<<i+1<<«. CLAN:»;
for(int j=0; j<br_mjeseci; j++){
cout<<«t»<<dzeparci[i][j];
}
cout<<endl;
}
cout<<«PROSJECNI DZEPARAC PO CLANU OBITELJI»<<endl;
for(int i=0; i<br_clanova; i++){
cout<<i+1<<«. CLAN:t»<<dzeparci_po_mjesecu[i]<<endl;
}
return 0;
}
thx
| description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
|---|---|---|---|---|---|
|
Learn more about: Fatal Error C1083 |
Fatal Error C1083 |
09/01/2017 |
C1083 |
C1083 |
97e52df3-e79c-4f85-8f1e-bbd1057d55e7 |
Cannot open filetype file: ‘file‘: message
The compiler generates a C1083 error when it can’t find a file it requires. There are many possible causes for this error. An incorrect include search path or missing or misnamed header files are the most common causes, but other file types and issues can also cause C1083. Here are some of the common reasons why the compiler generates this error.
The specified file name is wrong
The name of a file may be mistyped. For example,
#include <algorithm.h>
might not find the file you intend. Most C++ Standard Library header files do not have a .h file name extension. The <algorithm> header would not be found by this #include directive. To fix this issue, verify that the correct file name is entered, as in this example:
#include <algorithm>
Certain C Runtime Library headers are located in a subdirectory of the standard include directory. For example, to include sys/types.h, you must include the sys subdirectory name in the #include directive:
#include <sys/types.h>
The file is not included in the include search path
The compiler cannot find the file by using the search rules that are indicated by an #include or #import directive. For example, when a header file name is enclosed by quotation marks,
#include "myincludefile.h"
this tells the compiler to look for the file in the same directory that contains the source file first, and then look in other locations specified by the build environment. If the quotation marks contain an absolute path, the compiler only looks for the file at that location. If the quotation marks contain a relative path, the compiler looks for the file in the directory relative to the source directory.
If the name is enclosed by angle brackets,
#include <stdio.h>
the compiler follows a search path that is defined by the build environment, the /I compiler option, the /X compiler option, and the INCLUDE environment variable. For more information, including specific details about the search order used to find a file, see #include Directive (C/C++) and #import Directive.
If your include files are in another directory relative to your source directory, and you use a relative path in your include directives, you must use double quotes instead of angle brackets. For example, if your header file myheader.h is in a subdirectory of your project sources named headers, then this example fails to find the file and causes C1083:
#include <headersmyheader.h>
but this example works:
#include "headersmyheader.h"
Relative paths can also be used with directories on the include search path. If you add a directory to the INCLUDE environment variable or to your Include Directories path in Visual Studio, do not also add part of the path to the include directives. For example, if your header is located at pathexampleheadersmyheader.h, and you add pathexampleheaders to your Include Directories path in Visual Studio, but your #include directive refers to the file as
#include <headersmyheader.h>
then the file is not found. Use the correct path relative to the directory specified in the include search path. In this example, you could change the include search path to pathexample, or remove the headers path segment from the #include directive.
Third-party library issues and vcpkg
If you see this error when you are trying to configure a third-party library as part of your build, consider using vcpkg, a C++ package manager, to install and build the library. vcpkg supports a large and growing list of third-party libraries, and sets all the configuration properties and dependencies required for successful builds as part of your project.
The file is in your project, but not the include search path
Even when header files are listed in Solution Explorer as part of a project, the files are only found by the compiler when they are referred to by an #include or #import directive in a source file, and are located in an include search path. Different kinds of builds might use different search paths. The /X compiler option can be used to exclude directories from the include search path. This enables different builds to use different include files that have the same name, but are kept in different directories. This is an alternative to conditional compilation by using preprocessor commands. For more information about the /X compiler option, see /X (Ignore Standard Include Paths).
To fix this issue, correct the path that the compiler uses to search for the included or imported file. A new project uses default include search paths. You may have to modify the include search path to add a directory for your project. If you are compiling on the command line, add the path to the INCLUDE environment variable or the /I compiler option to specify the path to the file.
To set the include directory path in Visual Studio, open the project’s Property Pages dialog box. Select VC++ Directories under Configuration Properties in the left pane, and then edit the Include Directories property. For more information about the per-user and per-project directories searched by the compiler in Visual Studio, see VC++ Directories Property Page. For more information about the /I compiler option, see /I (Additional Include Directories).
The command line INCLUDE or LIB environment is not set
When the compiler is invoked on the command line, environment variables are often used to specify search paths. If the search path described by the INCLUDE or LIB environment variable is not set correctly, a C1083 error can be generated. We strongly recommend using a developer command prompt shortcut to set the basic environment for command line builds. For more information, see Build C/C++ on the Command Line. For more information about how to use environment variables, see How to: Use Environment Variables in a Build.
The file may be locked or in use
If you are using another program to edit or access the file, it may have the file locked. Try closing the file in the other program. Sometimes the other program can be Visual Studio itself, if you are using parallel compilation options. If turning off the parallel build option makes the error go away, then this is the problem. Other parallel build systems can also have this issue. Be careful to set file and project dependencies so build order is correct. In some cases, consider creating an intermediate project to force build dependency order for a common file that may be built by multiple projects. Sometimes antivirus programs temporarily lock recently changed files for scanning. If possible, consider excluding your project build directories from the antivirus scanner.
The wrong version of a file name is included
A C1083 error can also indicate that the wrong version of a file is included. For example, a build could include the wrong version of a file that has an #include directive for a header file that is not intended for that build. For example, certain files may only apply to x86 builds, or to Debug builds. When the header file is not found, the compiler generates a C1083 error. The fix for this problem is to use the correct file, not to add the header file or directory to the build.
The precompiled headers are not yet precompiled
When a project is configured to use precompiled headers, the relevant .pch files have to be created so that files that use the header contents can be compiled. For example, the pch.cpp file (stdafx.cpp in Visual Studio 2017 and earlier) is automatically created in the project directory for new projects. Compile that file first to create the precompiled header files. In the typical build process design, this is done automatically. For more information, see Creating Precompiled Header Files.
Additional causes
-
You have installed an SDK or third-party library, but you have not opened a new developer command prompt window after the SDK or library is installed. If the SDK or library adds files to the INCLUDE path, you may need to open a new developer command prompt window to pick up these environment variable changes.
-
The file uses managed code, but the compiler option
/clris not specified. For more information, see/clr(Common Language Runtime Compilation). -
The file is compiled by using a different
/analyzecompiler option setting than is used to precompile the headers. When the headers for a project are precompiled, all should use the same/analyzesettings. For more information, see/analyze(Code Analysis). -
The file or directory was created by the Windows Subsystem for Linux, per-directory case sensitivity is enabled, and the specified case of a path or file does not match the case of the path or file on disk.
-
The file, the directory, or the disk is read-only.
-
Visual Studio or the command line tools do not have sufficient permissions to read the file or the directory. This can happen, for example, when the project files have different ownership than the process running Visual Studio or the command line tools. Sometimes this issue can be fixed by running Visual Studio or the developer command prompt as Administrator.
-
There are not enough file handles. Close some applications and then recompile. This condition is unusual under typical circumstances. However, it can occur when large projects are built on a computer that has limited physical memory.
Example
The following example generates a C1083 error when the header file "test.h" does not exist in the source directory or on the include search path.
// C1083.cpp // compile with: /c #include "test.h" // C1083 test.h does not exist #include "stdio.h" // OK
For information about how to build C/C++ projects in the IDE or on the command line, and information about setting environment variables, see Projects and build systems.
See also
- MSBuild Properties
- Remove From My Forums
-
Question
-
Hi,
I’m using Visual C++ 2005 Express, and I see that this type of error message has been giving a lot of people problems, but after trying a few of the fixes posted here, my project still gets the same error message.
Here’s a snippet of my .h file:
//randomcard.hint randomcard(void)
{
int randomnum;and here’s the top part of my .cpp file:#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include «randomcard.h»
#include <iostream>;
Please let me know if you need anything else. I turned off the header «stdafx.h» hoping that would fix it…but it still doesn’t work.Thanks in advance!
nokomis
Answers
-
problem solved! I just deleted the header file and created a new one…the error message went away.
Thanks!
-
Hi nokomis,
Congrats!
At first glance, C1083 error seems to not be so significant. I think it actually means a lot. In terms of program organization, it indicates that you do not provide other separately compiled program segments with necessary interface info. In this context, I would say that you failed to define the problem that should be solved.
Coding is very important, of course. At the same time, program design is also important.Hope this helps.
- Remove From My Forums
-
Question
-
Hi,
I’m using Visual C++ 2005 Express, and I see that this type of error message has been giving a lot of people problems, but after trying a few of the fixes posted here, my project still gets the same error message.
Here’s a snippet of my .h file:
//randomcard.hint randomcard(void)
{
int randomnum;and here’s the top part of my .cpp file:#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include «randomcard.h»
#include <iostream>;
Please let me know if you need anything else. I turned off the header «stdafx.h» hoping that would fix it…but it still doesn’t work.Thanks in advance!
nokomis
Answers
-
problem solved! I just deleted the header file and created a new one…the error message went away.
Thanks!
-
Hi nokomis,
Congrats!
At first glance, C1083 error seems to not be so significant. I think it actually means a lot. In terms of program organization, it indicates that you do not provide other separately compiled program segments with necessary interface info. In this context, I would say that you failed to define the problem that should be solved.
Coding is very important, of course. At the same time, program design is also important.Hope this helps.
In VSC++, If I create a project with «Empty project» which is without «Precompiled header», the project will be empty, but if I wanted to use that #include "stdafx.h" inside my «Empty» project, it doesn’t works…
but if I create a project with «Precompiled header», it can work fine.
both the condition above having exactly the same code(Both have #include "stdafx.h" ), but only the one with «Precompile header» Project can work…
May I know how to solve this problem in «Empty Project»??
This is the error when creating the project in «Empty Project»
fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory 1>
lastly, Can I know what is #include "stdafx.h" for? Thanks…
but if I wanted to use that #include «stdafx.h» inside my «Empty» project, it doesn’t works…
Of course not. stdafx is the precompiled header. If you don’t have a precompiled header, then how can you include it?
May I know how to solve this problem in «Empty Project»??
It’s not really a problem. Just don’t include that header.
Or if you must (if you have dozens of files and you don’t want to modify them all), you can «fake» it by creating a blank file named «stdafx.h».
Can I know what is #include «stdafx.h» for?
When you #include a header file, it’s sort of like copy/pasting that header file into the cpp file. The compiler will walk through, examine, and compile that header whenever you compile the cpp file.
The compiler will do this process for every cpp file that includes that header. So if you have 100 cpp files in your project and they all include the same header, that header is being compiled 100 times.
If the header is very large, this might cause the computer to take a long time to compile your program. So compilers give you an option to «precompile» a header so that it compiles only once. Then each cpp file that #includes it does not have to re-compile it every time, they can just use the precompiled version. It can speed up compile time.
MSVS likes to name the default precompiled header «stdafx.h». But that’s all it is.
It’s worth noting that precompiled headers are completely worthless unless you are seeing slow compile times. I avoid them unless they make a significant difference in compile time.
Thanks…
Is that means #include "stdafx.h" is called precompiled header where as #include <iostream> , #include <conio.h> and so on is a library header? Or it’s call precompiled header as well?
From what u said, it’s completely worthless, is that means, without that #include "stdafx.h" , my system can works fine also?
Is that means #include «stdafx.h» is called precompiled header where as #include <iostream> , #include <conio.h> and so on is a library header?
Not really. A precompiled header can be named anything. «stdafx» is just the default name for it in VS.
Precompiling is a compiler setting. You can precompile any header, even library headers like <iostream>.
From what u said, it’s completely worthless, is that means, without that #include «stdafx.h» , my system can works fine also?
Yes. Enabling precompiled headers does absolutely nothing other than change how fast the compile can build the exe. The final program will be identical whether or not you use precompiled headers.
A precompiled header can be named anything.
If I named it as «ABC», it will works too?
Enabling precompiled headers does absolutely nothing other than change how fast the compile can build the exe.
U mean if have that #include "stdafx.h" , the system can build exe file faster? Is that what u mean? I though if we put more header, the time require to compile will be longer, am I right?
TQ….
If I named it as «ABC», it will works too?
Yes. The header can be named anything, as long as the compiler knows to precompile that header.
U mean if have that #include «stdafx.h» , the system can build exe file faster?
Yes, that’s the idea. Whether or not it REALLY makes it faster depends. Usually it won’t make much/any difference unless stdafx.h is a very big header.
I though if we put more header, the time require to compile will be longer, am I right?
Yes you are right.
Compile time is longer with more headers because the compiler had to compile each header when it is included.
However, if the headers are precompiled it doesn’t have to compile them because they have been precompiled already. Which is why it’s faster.
However, if the headers are precompiled it doesn’t have to compile them because they have been precompiled already. Which is why it’s faster.
But u said precompiled header has nothing to do with our program right? Then how to precompile my header since my header used is like #include <iostream> and #include <conio> but not #include "stdafx.h" …
Is that u mean in one program, I use many (let said 3) #include <iostream> and #include <conio> and if I include that Precompile header (#include «stdafx.h»), then it runs #include <iostream> and #include <conio> only once instead of 3 is it?
And another condition is I use many(let said 3) #include <iostream> and #include <conio> , but not include that Precompile header (#include «stdafx.h») this time, so, is that mean my program will runs #include <iostream> and #include <conio> 3 times?
Yes, that’s the idea. Whether or not it REALLY makes it faster depends. Usually it won’t make much/any difference unless stdafx.h is a very big header.
U mean stdafx.h is a big header? That header can be big? I thought it’s just a constant header which is same size(won’t change) with everyone? And somehow, if header is bigger, the time to compile should be longer right? But why big header become faster? Not really understand…can u help explain…
TQ…
Last edited on
The basic idea of precompiled header is: once parsed, used ever after.
Everything in this precompiled header (definitions or other includes) are put together in a file that is used instead of the precompiled header (#include «stdafx.h») itself. It’s supposed to be faster, because the compiler doesn’t need to open those includes and no more parsing is required.
You can put everything that doesn’t change (like #include <iostream> and #include <conio>) in that precomiled header. Only the project specific headers are left out.
That’s the idea.
The problem is that the precompiled file quickly becomes that hugh that navigating within is not faster then opening and parsing the headers when needed. Plus it turns out that the precompiled header file is error prone and you get problems while compiling.
The best is to disable precompiled header and forget about that once and forever.
Thanks coder776,
You can put everything that doesn’t change (like #include <iostream> and #include <conio>) in that precomiled header. Only the project specific headers are left out.
From here, can I know how to put them #include <iostream> and #include <conio> inside precompiled header (#include «stdafx.h»)? Example to the code below, how to put that 2 header inside stdafx.h? Thanks
|
|
Well, create a file in that directory where your main file is. Name it stdafx.h. Cut and copy line 1/2 to that file. the first line of your main file (and all other implementation files) must be #include «stdafx.h»
Thanks…
u mean create one main file which have the 1st line as #include «stdafx.h» and the next line will be the library header like the one below is it?
|
|
how about the rest? I mean is there anything after line 3? Or just need line 1-3? TQ…
Last edited on
no I mean that you create a file stdafx.h and place #include <iostream> and #include <conio> there.
in the file stdafx.h there’re only the lines 2 and 3.
the main file is the file where ‘int main()’ is. I don’t know how you named it. This would look like so:
Your main file:
|
|
stdafx.h
|
|
Last edited on
I think you’re missing some fundamental concept.
The compiler is going to parse and compile every included file every time it compiles a source file (which is every time you change a source file). So for an example, let’s say you have the following files:
|
|
|
|
|
|
|
|
When you build this project,
if you do not have a precompiled header
the compiler is going to compile the 2 source files main.cpp and support.cpp. When it does, it will do this:
Compiling main.cpp
— found #include «stdafx.h» in main.cpp, so start compiling stdafx.h
— found #include <windows.h> in stdafx.h, so start compiling windows.h
— found XXX other includes in windows.h, so compile all those headers as well
— found #include <iostream> in stdafx.h, so start compiling that header
— found XXX other includes in iostream, so compile all those as well
— found #include «myclass.h» in stdafx.h, so compile that header
— stdafx.h finish, continue compiling main.cpp
Compiling support.cpp
— found #include «stdafx.h» in support.cpp, so start compiling stdafx.h
— found #include <windows.h> in stdafx.h, so start compiling windows.h
— found XXX other includes in windows.h, so compile all those headers as well
— found #include <iostream> in stdafx.h, so start compiling that header
— found XXX other includes in iostream, so compile all those as well
— found #include «myclass.h» in stdafx.h, so compile that header
— stdafx.h finish, continue compiling support.cpp
Now…
if you make stdafx.h a precompiled header
, the compiler will do this instead:
PreCompiling stdafx.h
— found #include <windows.h> in stdafx.h, so start compiling windows.h
— found XXX other includes in windows.h, so compile all those headers as well
— found #include <iostream> in stdafx.h, so start compiling that header
— found XXX other includes in iostream, so compile all those as well
— found #include «myclass.h» in stdafx.h, so compile that header
— stdafx.h is now compiled, put compiled information in a new «stdafx.pch» file
Compiling main.cpp
— found #include «stdafx.h», but I already compiled that header, so no need to compile it again. Just use the info in the existing pch file.
— continue compiling main.cpp
Compiling support.cpp
— found #include «stdafx.h», but I already compiled that header, so no need to compile it again. Just use the info in the existing pch file.
— continue compiling support.cpp
That’s all it does. It just compiles the stuff once so it doesn’t need to be compiled every time.
Last edited on
Thanks coder777 and Disch
I think I understand already…
just another question for coder777, as u said
Well, create a file in that directory where your main file is. Name it stdafx.h. Cut and copy line 1/2 to that file. the first line of your main file (and all other implementation files) must be #include «stdafx.h»
first line of your main file (and all other implementation files) must be #include «stdafx.h»
is that must be 1st line? or any line before int main () are allow(maybe put the header after other library file) ? Is that ok? Thanks…