RSS

Category Archives: C++

Install OpenCV 2.4.3 on Visual Studio 2010

Advertisements
 
Leave a comment

Posted by on January 30, 2013 in C++

 

Tags:

Capture Video With OpenCV

#include "stdafx.h"
#include<opencv\cv.h>
#include<opencv\cxcore.h>
#include<opencv\highgui.h>

using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{

 CvCapture *capture = cvCaptureFromCAM(0);
 if( !capture ) return 1;
 cvNamedWindow("Video");

while(true) {

 IplImage* frame = cvQueryFrame( capture );
 if( !frame ) break;
 cvShowImage( "Video", frame );
 int c = cvWaitKey(40);
 if((char)c==20 ) break;
 }

cvDestroyWindow("Video");
 cvReleaseCapture( &capture );
 return 0;
}

&nbsp;

 
Leave a comment

Posted by on January 29, 2013 in C++

 

Tags:

Passing command line parameters

 #include <iostream>
 using namespace std;
 int main( int argc, char **argv )

{

//for taking command line arguments
bool numFound=false;
char myCharArray[10];
int x=argc;
int y;
cout <<"You entered  "<<x-1  <<" parameters after the command \"commandLine.\""<<endl;
cout <<"They were:  ";
for (int i=1; i<x; i++)
{
strcpy(myCharArray, argv[i]);
cout <<myCharArray<<"  ";
}

cout<<endl;
for (int i=1; i<x; i++)
{
strcpy(myCharArray, argv[i]);
if(isdigit(myCharArray[0]))
{

if(numFound==false)
cout<<"The number(s) you entered were:  ";

numFound=true;
y=atoi(argv[i]);
cout <<y<<" ";

}

}

cout <<endl;

}


 
 
Leave a comment

Posted by on November 25, 2011 in C++

 

Determine prime numbers


#include <iostream>

using namespace std;
int main()
{
int num=0;
int count=0;
int prime=1;
char ans=' ';
do
{
cout <<"Enter a number:  ";
cin >> num;
for (int i=(num)/2; i>1; i--)
{
if (num%i==0)
{
count=count+1;
if (count==1)
cout <<"Internal Factor(s):  ";
prime=0;
cout <<i<<" ";
}
}
if (prime==0)
{
cout<<"\nNumber is not prime."<<endl;
}
if (prime==1)
{
cout <<"Number is prime."<<endl;
}
cout<<"Do you wish to find another prime:  ";
cin>>ans;
cin.ignore(200,'\n');
count=0;
prime=1;
system("cls");
}while(ans =='y' || ans=='Y');
system("pause");
return 0;
}

 
Leave a comment

Posted by on November 25, 2011 in C++

 

Compiling a Native C++ Program from Command Line (C++)

1.Run Visual Studio 2008 Command Prompt window with Administrator privileges.
2.Set the following directory as the current directory at the command prompt: \Program Files\Microsoft Visual Studio <version>\VC.
3.In command prompt, type notepad sample.cpp and press Enter.

Click Yes when you are prompted to create a new file.
4. Type following code in notepad

#include <iostream>

int main()
{
std::cout << “This is a sample C++ program.” << std::endl;
return 0;
}

5.On the File menu, click Save. You have created a Visual C++ source file.

6.In command prompt, type cl /EHsc sample.cpp and press Enter. The /EHsc command-line option instructs the compiler to enable C++ exception handling

7.The cl.exe compiler generates an executable program sample.exe.The .obj file is an intermediate format file.

8.To run the sample.exe program, type simple and press Enter.

 
Leave a comment

Posted by on November 25, 2011 in C++