首页 \ 问答 \ 选择VS项目类型(C ++)(Choosing a VS project type (C++))

选择VS项目类型(C ++)(Choosing a VS project type (C++))

我并不多使用C ++(我试图坚持像Java和VB.NET这样的更简单的东西),但最近我没有选择。 当我在VS中选择项目类型时,我下载了一些C ++源代码,应该选择哪种项目类型? 我刚刚使用Win32控制台应用程序,但是我只是下载了一些代码(下文),即使编译出错时也不能正常工作。 我试图使用CLR控制台应用程序和一个空的项目,并且一直在改变许多变量,但我无法获得这个代码的工作。 我注意到这个代码在开始时并没有“ int main() ”,这与它有什么关系? 无论如何,这里是代码,从这里得到它:

/* Demo of modified Lucas-Kanade optical flow algorithm.
   See the printf below */

#ifdef _CH_
#pragma package <opencv>
#endif

#ifndef _EiC
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <ctype.h>
#endif

#include <windows.h>

#define FULL_IMAGE_AS_OUTPUT_FILE


#define cvMirror cvFlip

//IplImage *image = 0, *grey = 0, *prev_grey = 0, *pyramid = 0, *prev_pyramid = 0, *swap_temp;
IplImage **buf = 0;
IplImage *image1 = 0;
IplImage *imageCopy=0;

IplImage *image = 0;
int win_size = 10;
const int MAX_COUNT = 500;
CvPoint2D32f* points[2] = {0,0}, *swap_points;
char* status = 0;
//int count = 0;
//int need_to_init = 0;
//int night_mode = 0;
int flags = 0;
//int add_remove_pt = 0;
bool bLButtonDown = false;
//bool bstopLoop = false;
CvPoint pt, pt1,pt2;
//IplImage* img1;
FILE* FileDest;

char* strImageDir = "E:\\Projects\\TSCreator\\Images";
char* strItemName = "b";
int  imageCount=0;  
int bFirstFace = 1;     // flag for first face
int mode = 1; // Mode 1 - Haar Traing Sample Creation, 2 - HMM sample creation, Mode = 3 - Both Harr and HMM.
//int startImgeNo = 1;
bool isEqualRation = false; //Weidth to height ratio is equal

//Selected Image data
IplImage *selectedImage = 0;
int selectedX = 0, selectedY = 0, currentImageNo = 0, selectedWidth = 0, selectedHeight= 0;
CvRect selectedROI;


void saveFroHarrTraining(IplImage *src, int x, int y, int width, int height, int imageCount);
void saveForHMMTraining(IplImage *src, CvRect roi,int imageCount);

// Code for draw  ROI Cropping Image
void on_mouse( int event, int x, int y, int flags, void* param )
{

char f[200];
CvRect reg;

         if( !image )
            return;

    if( event == CV_EVENT_LBUTTONDOWN )
    {
        bLButtonDown = true;

        pt1.x = x;
        pt1.y = y;

    }
    else if ( event == CV_EVENT_MOUSEMOVE ) //Draw the selected area rectangle
    {
        pt2.x = x;
        pt2.y = y;

        if(bLButtonDown)
        {
            if( !image1 )
        {
            /* allocate all the buffers */
            image1 = cvCreateImage( cvGetSize(image), 8, 3 );
            image1->origin = image->origin;
            points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
            points[1] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
            status = (char*)cvAlloc(MAX_COUNT);
            flags = 0;
        }

        cvCopy( image, image1, 0 );     

        //Equal Weight-Height Ratio
            if(isEqualRation)
            {
                pt2.y = pt1.y + (pt2.x-pt1.x);
            }

            //Max Height and Width is the image width and height
            if(pt2.x>image->width)
            {
                pt2.x = image->width;
            }
            if(pt2.y>image->height)
            {
                pt2.y = image->height;
            }

            CvPoint InnerPt1 = pt1;
            CvPoint InnerPt2 = pt2;

            if ( InnerPt1.x > InnerPt2.x)
            {
                int tempX = InnerPt1.x;
                InnerPt1.x = InnerPt2.x;
                InnerPt2.x = tempX;
            }

            if ( pt2.y < InnerPt1.y )
            {
                int tempY = InnerPt1.y;
                InnerPt1.y = InnerPt2.y;
                InnerPt2.y = tempY;

            }

            InnerPt1.y = image->height - InnerPt1.y;
            InnerPt2.y = image->height - InnerPt2.y;    




            CvFont font;
            double hScale=1.0;
            double vScale=1.0;
            int    lineWidth=1;
            cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, hScale,vScale,0,lineWidth);

            char size [200];
            reg.x = pt1.x;
            reg.y = image->height - pt2.y;
            reg.height = abs (pt2.y - pt1.y);
            reg.width = InnerPt2.x -InnerPt1.x;
            //print width and heght of the selected reagion
            sprintf(size, "(%dx%d)",reg.width, reg.height);
            cvPutText (image1,size,cvPoint(10,10), &font, cvScalar(255,255,0));
            cvRectangle(image1, InnerPt1, InnerPt2, CV_RGB(255,0,0), 1);

            //Mark Selected Reagion
            selectedImage = image;
            selectedX = pt1.x;
            selectedY = pt1.y;
            selectedWidth = reg.width;
            selectedHeight = reg.height;
            selectedROI  = reg;

            //Show the modified image
            cvShowImage("HMM-Harr Positive Image Creator",image1);
        }

    }
    else if ( event == CV_EVENT_LBUTTONUP )
    {
        bLButtonDown = false;

//      pt2.x = x;
//      pt2.y = y;
//
//      if ( pt1.x > pt2.x)
//      {
//          int tempX = pt1.x;
//          pt1.x = pt2.x;
//          pt2.x = tempX;
//      }
//
//      if ( pt2.y < pt1.y )
//      {
//          int tempY = pt1.y;
//          pt1.y = pt2.y;
//          pt2.y = tempY;
//
//      }
//
//reg.x = pt1.x;
//reg.y = image->height - pt2.y;
//
//reg.height = abs (pt2.y - pt1.y);
////reg.width = reg.height/3;
//reg.width = pt2.x -pt1.x;
////reg.height = (2 * reg.width)/3;



#ifdef FULL_IMAGE_AS_OUTPUT_FILE
        CvRect FullImageRect;
        FullImageRect.x = 0;
        FullImageRect.y = 0;
        FullImageRect.width = image->width;
        FullImageRect.height = image->height;   

        IplImage *regionFullImage =0;
        regionFullImage = cvCreateImage(cvSize (FullImageRect.width, FullImageRect.height),
                                    image->depth, image->nChannels);

        image->roi = NULL;

        //cvSetImageROI (image, FullImageRect);
        //cvCopy (image, regionFullImage, 0);

#else
         IplImage *region =0;
         region = cvCreateImage(cvSize (reg.width, reg.height),            
                                image1->depth, image1->nChannels);

        image->roi = NULL;
        cvSetImageROI (image1, reg);

        cvCopy (image1, region, 0);
#endif
        //cvNamedWindow("Result", CV_WINDOW_AUTOSIZE);

        //selectedImage = image;
        //selectedX = pt1.x;
        //selectedY = pt1.y;
        //selectedWidth = reg.width;
        //selectedHeight = reg.height;
        ////currentImageNo = startImgeNo;
        //selectedROI  = reg;

        /*if(mode == 1)
        {
            saveFroHarrTraining(image,pt1.x,pt1.y,reg.width,reg.height,startImgeNo);
        }
        else if(mode == 2)
        {
            saveForHMMTraining(image,reg,startImgeNo);
        }
        else if(mode ==3)
        {
            saveFroHarrTraining(image,pt1.x,pt1.y,reg.width,reg.height,startImgeNo);
            saveForHMMTraining(image,reg,startImgeNo);
        }
        else
        {
            printf("Invalid mode.");
        }


        startImgeNo++;*/

    }
}

/*
Save popsitive samples for Harr Training. 
Also add an entry to the PositiveSample.txt with the location of the item of interest.
*/
void saveFroHarrTraining(IplImage *src, int x, int y, int width, int height, int imageCount)
{
    char f[255] ;
        sprintf(f,"%s\\%s\\harr_%s%d%d.jpg",strImageDir,strItemName,strItemName,imageCount/10, imageCount%10);

        cvNamedWindow("Harr", CV_WINDOW_AUTOSIZE);
        cvShowImage("Harr", src);
        cvSaveImage(f, src);


        printf("output%d%d \t ", imageCount/10, imageCount%10);
        printf("width %d \t", width);
        printf("height %d \t", height);
        printf("x1 %d \t", x);
        printf("y1 %d \t\n", y);

        char f1[255];
        sprintf(f1,"%s\\PositiveSample.txt",strImageDir);
        FileDest = fopen(f1, "a");
        fprintf(FileDest, "%s\\harr_%s%d.jpg 1 %d %d %d %d  \n",strItemName,strItemName, imageCount, x, y, width, height);
        fclose(FileDest);
}

/*
Create Sample Images for HMM recognition algorythm trai ning.
*/
void saveForHMMTraining(IplImage *src, CvRect roi,int imageCount)
{
    char f[255] ;
    printf("x=%d, y=%d, w= %d, h= %d\n",roi.x,roi.y,roi.width,roi.height);
    //Create the file name
    sprintf(f,"%s\\%s\\hmm_%s%d.pgm",strImageDir,strItemName,strItemName, imageCount);

    //Create storage for grayscale image
    IplImage* gray = cvCreateImage(cvSize(roi.width,roi.height), 8, 1);
    //Create storage for croped reagon
    IplImage* regionFullImage = cvCreateImage(cvSize(roi.width,roi.height),8,3);
    //Croped marked region
    cvSetImageROI(src,roi);
    cvCopy(src,regionFullImage);
    cvResetImageROI(src);
    //Flip croped image - otherwise it will saved upside down
    cvConvertImage(regionFullImage, regionFullImage, CV_CVTIMG_FLIP);
    //Convert croped image to gray scale
    cvCvtColor(regionFullImage,gray, CV_BGR2GRAY);
    //Show final grayscale image
    cvNamedWindow("HMM", CV_WINDOW_AUTOSIZE);
    cvShowImage("HMM", gray);
    //Save final grayscale image
    cvSaveImage(f, gray);
}

int maina( int argc, char** argv )
{
    CvCapture* capture = 0;
    //if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
    //    capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
    //else if( argc == 2 )
    //    capture = cvCaptureFromAVI( argv[1] );

    char* video;

    if(argc ==7)
    {
        mode = atoi(argv[1]);
        strImageDir = argv[2];
        strItemName = argv[3];
        video = argv[4];
        currentImageNo = atoi(argv[5]);
        int a = atoi(argv[6]);
        if(a==1)
        {
            isEqualRation = true;
        }
        else
        {
            isEqualRation = false;
        }

    }
    else
    {
        printf("\nUsage: TSCreator.exe <Mode> <Sample Image Save Path> <Sample Image Save Directory> <Video File Location> <Start Image No> <Is Equal Ratio>\n");
        printf("Mode = 1 - Haar Traing Sample Creation. \nMode = 2 - HMM sample creation.\nMode = 3 - Both Harr and HMM\n");
        printf("Is Equal Ratio = 0 or 1. 1 - Equal weidth and height, 0 - custom.");
        printf("Note: You have to create the image save directory in correct path first.\n");
        printf("Eg: TSCreator.exe 1 E:\Projects\TSCreator\Images A 11.avi 1 1\n\n");
        return 0;
    }
      capture = cvCaptureFromAVI(video);

    if( !capture )
    {
        fprintf(stderr,"Could not initialize capturing...\n");
        return -1;
    }

    cvNamedWindow("HMM-Harr Positive Image Creator", CV_WINDOW_AUTOSIZE);
    cvSetMouseCallback("HMM-Harr Positive Image Creator", on_mouse, 0);
    //cvShowImage("Test", image1);

    for(;;)
    {
        IplImage* frame = 0;
        int i, k, c;

        frame = cvQueryFrame( capture );
        if( !frame )
            break; 

        if( !image )
        {
            /* allocate all the buffers */
            image = cvCreateImage( cvGetSize(frame), 8, 3 );
            image->origin = frame->origin;
            //grey = cvCreateImage( cvGetSize(frame), 8, 1 );
            //prev_grey = cvCreateImage( cvGetSize(frame), 8, 1 );
            //pyramid = cvCreateImage( cvGetSize(frame), 8, 1 );
           // prev_pyramid = cvCreateImage( cvGetSize(frame), 8, 1 );
            points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
            points[1] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
            status = (char*)cvAlloc(MAX_COUNT);
            flags = 0;
        }

        cvCopy( frame, image, 0 );
       // cvCvtColor( image, grey, CV_BGR2GRAY );


        cvShowImage("HMM-Harr Positive Image Creator", image);
        cvSetMouseCallback("HMM-Harr Positive Image Creator", on_mouse, 0);
         c = cvWaitKey(0);
         if((char)c == 's')
         {
            //Save selected reagion as training data
             if(selectedImage)
             {
                 printf("Selected Reagion Saved\n");
                if(mode == 1)
                {
                    saveFroHarrTraining(selectedImage,selectedX,selectedY,selectedWidth,selectedHeight,currentImageNo);
                }
                else if(mode == 2)
                {
                    saveForHMMTraining(selectedImage,selectedROI,currentImageNo);
                }
                else if(mode ==3)
                {
                    saveFroHarrTraining(selectedImage,selectedX,selectedY,selectedWidth,selectedHeight,currentImageNo);
                    saveForHMMTraining(selectedImage,selectedROI,currentImageNo);
                }
                else
                {
                    printf("Invalid mode.");
                }
                currentImageNo++;
             }      

         }

    }

    cvReleaseCapture( &capture );
    //cvDestroyWindow("HMM-Harr Positive Image Creator");
    cvDestroyAllWindows();

    return 0;
}

#ifdef _EiC
main(1,"lkdemo.c");
#endif

如果我把...

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

...之前的代码(并将其链接到正确的OpenCV .lib文件)它编译时没有错误,但在命令行中不做任何事情。 我如何使它工作?


I do not use C++ much (I try to stick to the easier stuff like Java and VB.NET), but the lately I have not had a choice. When I am picking a project type in VS for some C++ source I download, what project type should I pick? I had just been sticking with Win32 Console Applications, but I just downloaded some code (below) that will not work right even when it compiles with out errors. I have tried to use a CLR Console Application and an empty project too, and have changed many variables along the way, but I cannot get this code to work. I noticed that this code does not have "int main()" at its beginning, does that have something to do with it? Anyways, here is the code, got it from here:

/* Demo of modified Lucas-Kanade optical flow algorithm.
   See the printf below */

#ifdef _CH_
#pragma package <opencv>
#endif

#ifndef _EiC
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <ctype.h>
#endif

#include <windows.h>

#define FULL_IMAGE_AS_OUTPUT_FILE


#define cvMirror cvFlip

//IplImage *image = 0, *grey = 0, *prev_grey = 0, *pyramid = 0, *prev_pyramid = 0, *swap_temp;
IplImage **buf = 0;
IplImage *image1 = 0;
IplImage *imageCopy=0;

IplImage *image = 0;
int win_size = 10;
const int MAX_COUNT = 500;
CvPoint2D32f* points[2] = {0,0}, *swap_points;
char* status = 0;
//int count = 0;
//int need_to_init = 0;
//int night_mode = 0;
int flags = 0;
//int add_remove_pt = 0;
bool bLButtonDown = false;
//bool bstopLoop = false;
CvPoint pt, pt1,pt2;
//IplImage* img1;
FILE* FileDest;

char* strImageDir = "E:\\Projects\\TSCreator\\Images";
char* strItemName = "b";
int  imageCount=0;  
int bFirstFace = 1;     // flag for first face
int mode = 1; // Mode 1 - Haar Traing Sample Creation, 2 - HMM sample creation, Mode = 3 - Both Harr and HMM.
//int startImgeNo = 1;
bool isEqualRation = false; //Weidth to height ratio is equal

//Selected Image data
IplImage *selectedImage = 0;
int selectedX = 0, selectedY = 0, currentImageNo = 0, selectedWidth = 0, selectedHeight= 0;
CvRect selectedROI;


void saveFroHarrTraining(IplImage *src, int x, int y, int width, int height, int imageCount);
void saveForHMMTraining(IplImage *src, CvRect roi,int imageCount);

// Code for draw  ROI Cropping Image
void on_mouse( int event, int x, int y, int flags, void* param )
{

char f[200];
CvRect reg;

         if( !image )
            return;

    if( event == CV_EVENT_LBUTTONDOWN )
    {
        bLButtonDown = true;

        pt1.x = x;
        pt1.y = y;

    }
    else if ( event == CV_EVENT_MOUSEMOVE ) //Draw the selected area rectangle
    {
        pt2.x = x;
        pt2.y = y;

        if(bLButtonDown)
        {
            if( !image1 )
        {
            /* allocate all the buffers */
            image1 = cvCreateImage( cvGetSize(image), 8, 3 );
            image1->origin = image->origin;
            points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
            points[1] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
            status = (char*)cvAlloc(MAX_COUNT);
            flags = 0;
        }

        cvCopy( image, image1, 0 );     

        //Equal Weight-Height Ratio
            if(isEqualRation)
            {
                pt2.y = pt1.y + (pt2.x-pt1.x);
            }

            //Max Height and Width is the image width and height
            if(pt2.x>image->width)
            {
                pt2.x = image->width;
            }
            if(pt2.y>image->height)
            {
                pt2.y = image->height;
            }

            CvPoint InnerPt1 = pt1;
            CvPoint InnerPt2 = pt2;

            if ( InnerPt1.x > InnerPt2.x)
            {
                int tempX = InnerPt1.x;
                InnerPt1.x = InnerPt2.x;
                InnerPt2.x = tempX;
            }

            if ( pt2.y < InnerPt1.y )
            {
                int tempY = InnerPt1.y;
                InnerPt1.y = InnerPt2.y;
                InnerPt2.y = tempY;

            }

            InnerPt1.y = image->height - InnerPt1.y;
            InnerPt2.y = image->height - InnerPt2.y;    




            CvFont font;
            double hScale=1.0;
            double vScale=1.0;
            int    lineWidth=1;
            cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, hScale,vScale,0,lineWidth);

            char size [200];
            reg.x = pt1.x;
            reg.y = image->height - pt2.y;
            reg.height = abs (pt2.y - pt1.y);
            reg.width = InnerPt2.x -InnerPt1.x;
            //print width and heght of the selected reagion
            sprintf(size, "(%dx%d)",reg.width, reg.height);
            cvPutText (image1,size,cvPoint(10,10), &font, cvScalar(255,255,0));
            cvRectangle(image1, InnerPt1, InnerPt2, CV_RGB(255,0,0), 1);

            //Mark Selected Reagion
            selectedImage = image;
            selectedX = pt1.x;
            selectedY = pt1.y;
            selectedWidth = reg.width;
            selectedHeight = reg.height;
            selectedROI  = reg;

            //Show the modified image
            cvShowImage("HMM-Harr Positive Image Creator",image1);
        }

    }
    else if ( event == CV_EVENT_LBUTTONUP )
    {
        bLButtonDown = false;

//      pt2.x = x;
//      pt2.y = y;
//
//      if ( pt1.x > pt2.x)
//      {
//          int tempX = pt1.x;
//          pt1.x = pt2.x;
//          pt2.x = tempX;
//      }
//
//      if ( pt2.y < pt1.y )
//      {
//          int tempY = pt1.y;
//          pt1.y = pt2.y;
//          pt2.y = tempY;
//
//      }
//
//reg.x = pt1.x;
//reg.y = image->height - pt2.y;
//
//reg.height = abs (pt2.y - pt1.y);
////reg.width = reg.height/3;
//reg.width = pt2.x -pt1.x;
////reg.height = (2 * reg.width)/3;



#ifdef FULL_IMAGE_AS_OUTPUT_FILE
        CvRect FullImageRect;
        FullImageRect.x = 0;
        FullImageRect.y = 0;
        FullImageRect.width = image->width;
        FullImageRect.height = image->height;   

        IplImage *regionFullImage =0;
        regionFullImage = cvCreateImage(cvSize (FullImageRect.width, FullImageRect.height),
                                    image->depth, image->nChannels);

        image->roi = NULL;

        //cvSetImageROI (image, FullImageRect);
        //cvCopy (image, regionFullImage, 0);

#else
         IplImage *region =0;
         region = cvCreateImage(cvSize (reg.width, reg.height),            
                                image1->depth, image1->nChannels);

        image->roi = NULL;
        cvSetImageROI (image1, reg);

        cvCopy (image1, region, 0);
#endif
        //cvNamedWindow("Result", CV_WINDOW_AUTOSIZE);

        //selectedImage = image;
        //selectedX = pt1.x;
        //selectedY = pt1.y;
        //selectedWidth = reg.width;
        //selectedHeight = reg.height;
        ////currentImageNo = startImgeNo;
        //selectedROI  = reg;

        /*if(mode == 1)
        {
            saveFroHarrTraining(image,pt1.x,pt1.y,reg.width,reg.height,startImgeNo);
        }
        else if(mode == 2)
        {
            saveForHMMTraining(image,reg,startImgeNo);
        }
        else if(mode ==3)
        {
            saveFroHarrTraining(image,pt1.x,pt1.y,reg.width,reg.height,startImgeNo);
            saveForHMMTraining(image,reg,startImgeNo);
        }
        else
        {
            printf("Invalid mode.");
        }


        startImgeNo++;*/

    }
}

/*
Save popsitive samples for Harr Training. 
Also add an entry to the PositiveSample.txt with the location of the item of interest.
*/
void saveFroHarrTraining(IplImage *src, int x, int y, int width, int height, int imageCount)
{
    char f[255] ;
        sprintf(f,"%s\\%s\\harr_%s%d%d.jpg",strImageDir,strItemName,strItemName,imageCount/10, imageCount%10);

        cvNamedWindow("Harr", CV_WINDOW_AUTOSIZE);
        cvShowImage("Harr", src);
        cvSaveImage(f, src);


        printf("output%d%d \t ", imageCount/10, imageCount%10);
        printf("width %d \t", width);
        printf("height %d \t", height);
        printf("x1 %d \t", x);
        printf("y1 %d \t\n", y);

        char f1[255];
        sprintf(f1,"%s\\PositiveSample.txt",strImageDir);
        FileDest = fopen(f1, "a");
        fprintf(FileDest, "%s\\harr_%s%d.jpg 1 %d %d %d %d  \n",strItemName,strItemName, imageCount, x, y, width, height);
        fclose(FileDest);
}

/*
Create Sample Images for HMM recognition algorythm trai ning.
*/
void saveForHMMTraining(IplImage *src, CvRect roi,int imageCount)
{
    char f[255] ;
    printf("x=%d, y=%d, w= %d, h= %d\n",roi.x,roi.y,roi.width,roi.height);
    //Create the file name
    sprintf(f,"%s\\%s\\hmm_%s%d.pgm",strImageDir,strItemName,strItemName, imageCount);

    //Create storage for grayscale image
    IplImage* gray = cvCreateImage(cvSize(roi.width,roi.height), 8, 1);
    //Create storage for croped reagon
    IplImage* regionFullImage = cvCreateImage(cvSize(roi.width,roi.height),8,3);
    //Croped marked region
    cvSetImageROI(src,roi);
    cvCopy(src,regionFullImage);
    cvResetImageROI(src);
    //Flip croped image - otherwise it will saved upside down
    cvConvertImage(regionFullImage, regionFullImage, CV_CVTIMG_FLIP);
    //Convert croped image to gray scale
    cvCvtColor(regionFullImage,gray, CV_BGR2GRAY);
    //Show final grayscale image
    cvNamedWindow("HMM", CV_WINDOW_AUTOSIZE);
    cvShowImage("HMM", gray);
    //Save final grayscale image
    cvSaveImage(f, gray);
}

int maina( int argc, char** argv )
{
    CvCapture* capture = 0;
    //if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
    //    capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
    //else if( argc == 2 )
    //    capture = cvCaptureFromAVI( argv[1] );

    char* video;

    if(argc ==7)
    {
        mode = atoi(argv[1]);
        strImageDir = argv[2];
        strItemName = argv[3];
        video = argv[4];
        currentImageNo = atoi(argv[5]);
        int a = atoi(argv[6]);
        if(a==1)
        {
            isEqualRation = true;
        }
        else
        {
            isEqualRation = false;
        }

    }
    else
    {
        printf("\nUsage: TSCreator.exe <Mode> <Sample Image Save Path> <Sample Image Save Directory> <Video File Location> <Start Image No> <Is Equal Ratio>\n");
        printf("Mode = 1 - Haar Traing Sample Creation. \nMode = 2 - HMM sample creation.\nMode = 3 - Both Harr and HMM\n");
        printf("Is Equal Ratio = 0 or 1. 1 - Equal weidth and height, 0 - custom.");
        printf("Note: You have to create the image save directory in correct path first.\n");
        printf("Eg: TSCreator.exe 1 E:\Projects\TSCreator\Images A 11.avi 1 1\n\n");
        return 0;
    }
      capture = cvCaptureFromAVI(video);

    if( !capture )
    {
        fprintf(stderr,"Could not initialize capturing...\n");
        return -1;
    }

    cvNamedWindow("HMM-Harr Positive Image Creator", CV_WINDOW_AUTOSIZE);
    cvSetMouseCallback("HMM-Harr Positive Image Creator", on_mouse, 0);
    //cvShowImage("Test", image1);

    for(;;)
    {
        IplImage* frame = 0;
        int i, k, c;

        frame = cvQueryFrame( capture );
        if( !frame )
            break; 

        if( !image )
        {
            /* allocate all the buffers */
            image = cvCreateImage( cvGetSize(frame), 8, 3 );
            image->origin = frame->origin;
            //grey = cvCreateImage( cvGetSize(frame), 8, 1 );
            //prev_grey = cvCreateImage( cvGetSize(frame), 8, 1 );
            //pyramid = cvCreateImage( cvGetSize(frame), 8, 1 );
           // prev_pyramid = cvCreateImage( cvGetSize(frame), 8, 1 );
            points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
            points[1] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
            status = (char*)cvAlloc(MAX_COUNT);
            flags = 0;
        }

        cvCopy( frame, image, 0 );
       // cvCvtColor( image, grey, CV_BGR2GRAY );


        cvShowImage("HMM-Harr Positive Image Creator", image);
        cvSetMouseCallback("HMM-Harr Positive Image Creator", on_mouse, 0);
         c = cvWaitKey(0);
         if((char)c == 's')
         {
            //Save selected reagion as training data
             if(selectedImage)
             {
                 printf("Selected Reagion Saved\n");
                if(mode == 1)
                {
                    saveFroHarrTraining(selectedImage,selectedX,selectedY,selectedWidth,selectedHeight,currentImageNo);
                }
                else if(mode == 2)
                {
                    saveForHMMTraining(selectedImage,selectedROI,currentImageNo);
                }
                else if(mode ==3)
                {
                    saveFroHarrTraining(selectedImage,selectedX,selectedY,selectedWidth,selectedHeight,currentImageNo);
                    saveForHMMTraining(selectedImage,selectedROI,currentImageNo);
                }
                else
                {
                    printf("Invalid mode.");
                }
                currentImageNo++;
             }      

         }

    }

    cvReleaseCapture( &capture );
    //cvDestroyWindow("HMM-Harr Positive Image Creator");
    cvDestroyAllWindows();

    return 0;
}

#ifdef _EiC
main(1,"lkdemo.c");
#endif

If I put...

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

... before the previous code (and link it to the correct OpenCV .lib files) it compiles without errors, but does nothing at the command line. How do I make it work?


原文:https://stackoverflow.com/questions/2513200
更新时间:2023-07-04 19:07

最满意答案

注意:据我所知,在Firebase中直接使用自定义身份验证系统是不可能的。

假设:您有一个可以集成Firebase Admin SDK(可以/已经)的认证服务器。

您需要创建自定义令牌才能在数据库/存储中使用您的身份验证:

https://firebase.google.com/docs/auth/admin/create-custom-tokens

通过身份验证后,此身份将用于访问其他Firebase服务,例如Firebase实时数据库和云端存储。 此外,JWT的内容将在您的Firebase实时数据库安全规则中的auth对象以及Cloud Storage安全规则中的request.auth对象中提供。

从上面的链接中省略Java和Python

在服务器中:

// Step 1: Your client has sent the credentials.
// Step 2: Fetch the client's unique id, and create a custom token with the Admin SDK.

var uid = "some-uid"; 

admin.auth().createCustomToken(uid)
  .then(function(customToken) {
    // Send token back to client
  })
  .catch(function(error) {
    console.log("Error creating custom token:", error);
  });

然后在iOS部分:

// Step 1: Login with your own authentication system.
// Step 2: Send your credentials to your server, and fetch the customToken.
// Step 3: Sign in with FIRAuth:

[[FIRAuth auth] signInWithCustomToken:customToken
                           completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
  // ...
}];

Note: To my knowledge, it's not possible to use your custom authentication system directly within Firebase.

Assumption: You have an authentication server which Firebase Admin SDK (can be/has already been) integrated.

You need to create custom tokens in order to use your authentication within the Database/Storage:

https://firebase.google.com/docs/auth/admin/create-custom-tokens

Once authenticated, this identity will be used when accessing other Firebase services, such as the Firebase Realtime Database and Cloud Storage. Furthermore, the contents of the JWT will be available in the auth object in your Firebase Realtime Database Security Rules and the request.auth object in your Cloud Storage Security Rules.

Omitting Java and Python from the upper link

In server:

// Step 1: Your client has sent the credentials.
// Step 2: Fetch the client's unique id, and create a custom token with the Admin SDK.

var uid = "some-uid"; 

admin.auth().createCustomToken(uid)
  .then(function(customToken) {
    // Send token back to client
  })
  .catch(function(error) {
    console.log("Error creating custom token:", error);
  });

Then in iOS part:

// Step 1: Login with your own authentication system.
// Step 2: Send your credentials to your server, and fetch the customToken.
// Step 3: Sign in with FIRAuth:

[[FIRAuth auth] signInWithCustomToken:customToken
                           completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
  // ...
}];

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)