示例#1
0
文件: fileio.c 项目: Bot007/openOCD
int nand_fileio_start(struct command_context *cmd_ctx,
	struct nand_device *nand, const char *filename, int filemode,
	struct nand_fileio_state *state)
{
	if (state->address % nand->page_size) {
		command_print(cmd_ctx, "only page-aligned addresses are supported");
		return ERROR_COMMAND_SYNTAX_ERROR;
	}

	duration_start(&state->bench);

	if (NULL != filename) {
		int retval = fileio_open(&state->fileio, filename, filemode, FILEIO_BINARY);
		if (ERROR_OK != retval) {
			const char *msg = (FILEIO_READ == filemode) ? "read" : "write";
			command_print(cmd_ctx, "failed to open '%s' for %s access",
				filename, msg);
			return retval;
		}
		state->file_opened = true;
	}

	if (!(state->oob_format & NAND_OOB_ONLY)) {
		state->page_size = nand->page_size;
		state->page = malloc(nand->page_size);
	}

	if (state->oob_format & (NAND_OOB_RAW | NAND_OOB_SW_ECC | NAND_OOB_SW_ECC_KW)) {
		if (nand->page_size == 512) {
			state->oob_size = 16;
			state->eccpos = nand_oob_16.eccpos;
		} else if (nand->page_size == 2048)   {
			state->oob_size = 64;
			state->eccpos = nand_oob_64.eccpos;
		}
		state->oob = malloc(state->oob_size);
	}

	return ERROR_OK;
}
示例#2
0
int main(int argc, char** argv)
{
    IplImage *mOrigFrame = NULL;
    IplImage *resizedImg = NULL;
    IplImage *detectedImg = NULL;
    IplImage *faceNotFoundImg = NULL;
    IplImage *thresholdedImg = NULL;    //二级化
    IplImage *histogramEqualizatedImg = NULL; //histogram equalization

    IplImage *yuvImg = NULL;
    IplImage *maskImage = NULL;
    //these channels some times stands for R,G,B or Y,Cr,Cb channel
    IplImage *channel_0 = NULL;
    IplImage *channel_1 = NULL;
    IplImage *channel_2 = NULL;

    CvRect faceRect;

    for(int i =0; i < argc; i++){
        LOGD("argv[%d] = %s", i, argv[i]);
    }
    switch (argc) {
        case 2:
            mCascadeFile = argv[1];
        case 3:
            ;
        default:
            break;
    }

    mCvCapture = cvCreateCameraCapture(CV_CAP_ANY);

    mFrame = cvCreateImage(getCaptureSize(mCvCapture), IPL_DEPTH_8U, 3);  
    DUMP_IMAGE(mFrame);
    yuvImg = cvCreateImage(cvGetSize(mFrame), mFrame->depth, mFrame->nChannels);
    DUMP_IMAGE(yuvImg);
    faceNotFoundImg = cvLoadImage("./face_not_found.bmp");
    DUMP_IMAGE(faceNotFoundImg);
    maskImage = cvCreateImage(cvGetSize(mFrame), IPL_DEPTH_8U, 1);
    DUMP_IMAGE(maskImage);
    channel_0 = cvCreateImage(cvGetSize(mFrame), IPL_DEPTH_8U, 1);
    DUMP_IMAGE(channel_0);
    channel_1 = cvCreateImage(cvGetSize(mFrame), IPL_DEPTH_8U, 1);
    channel_2 = cvCreateImage(cvGetSize(mFrame), IPL_DEPTH_8U, 1);

    // Create a window in which the captured images will be presented
    //cvNamedWindow( "window_0", CV_WINDOW_AUTOSIZE );
    cvNamedWindow("window_1", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("window_2", CV_WINDOW_AUTOSIZE);
    cvMoveWindow("window_1", 600, 100);

DURATION_START;
    mFaceCascade = (CvHaarClassifierCascade*)cvLoad(mCascadeFile, 0, 0, 0 );
DURATION_STOP("load cascade file");
    
    int frame_count = 0;
    bool detect_res = false;
    float scale_ratio = 0;
    

    duration_start();
    for(; ; frame_count ++) {
        mOrigFrame= cvQueryFrame(mCvCapture);
        if (mOrigFrame) {
            LOGD("capture %d frame", frame_count);
            cvCopy(mOrigFrame, mFrame);
        }

        if(mFrame->origin == IPL_ORIGIN_BL) {
            LOGD("need FLIP");
            cvFlip(mFrame, mFrame, 0);
        }

        //cvShowImage("window_0", mFrame);

        cvZero(maskImage);
        cvCvtColor(mFrame, yuvImg, CV_BGR2YCrCb);

        cvSetImageCOI(yuvImg,2);//channel Cr
        cvCopy(yuvImg, channel_1);
        cvSetImageCOI(yuvImg, 3);//channel Cb
        cvCopy(yuvImg, channel_2);
        cvSetImageCOI(yuvImg,0);//reset

        for(int i = 0; i < mFrame->height; i++) {
            for(int j = 0; j < mFrame->width; j ++) {
                if( ((unsigned char *)(channel_1->imageData + i * channel_1->widthStep))[j] >= 123
                 && ((unsigned char *)(channel_1->imageData + i * channel_1->widthStep))[j] <= 175 
                 && ((unsigned char *)(channel_2->imageData + i * channel_2->widthStep))[j] >= 93
                 && ((unsigned char *)(channel_2->imageData + i * channel_2->widthStep))[j] <= 133) {

                    ((unsigned char *)(maskImage->imageData + i * maskImage->widthStep))[j] = 255;
                 }
            }
        }

        cvShowImage("window_1", mFrame);
        cvCopy(mFrame, yuvImg, maskImage);
        //cvShowImage("window_2", yuvImg);
        cvShowImage("window_2", maskImage);



        //resizedImg = resizeImage(mFrame);
        //scale_ratio = ((float) (mFrame->width)) / resizedImg->width;
        //LOGD("scale_ratio = %f", scale_ratio);
        
/*
//DURATION_START;
        detect_res = face_detect(resizedImg, mFaceCascade, &faceRect);
//DURATION_STOP("face_detect");

        if(detect_res){
            //LOGD("detected zone:(%d,%d) with %dx%d", faceRect.x, faceRect.y, faceRect.width, faceRect.height);
            detectedImg = cvCreateImage(cvSize(faceRect.width, faceRect.height), IPL_DEPTH_8U, 1);
            cvSetImageROI(resizedImg, faceRect);
            cvResize(resizedImg, detectedImg);
            cvResetImageROI(resizedImg);

            thresholdedImg = cvCreateImage(cvGetSize(detectedImg), detectedImg->depth, detectedImg->nChannels);
            histogramEqualizatedImg = cvCreateImage(cvGetSize(detectedImg), detectedImg->depth, detectedImg->nChannels);
            cvThreshold(detectedImg, thresholdedImg, 80, 255, CV_THRESH_BINARY);    //二级化``
            cvEqualizeHist(detectedImg, histogramEqualizatedImg);

            cvShowImage("window_1", histogramEqualizatedImg);
            
            cvReleaseImage(&resizedImg);
            cvReleaseImage(&detectedImg);
            cvReleaseImage(&thresholdedImg);
            cvReleaseImage(&histogramEqualizatedImg);
        }else{
            //LOGD("face NOT founded");
            cvShowImage("window_1", faceNotFoundImg);
        }
*/

        //press 'esc' to stop
        if ( (cvWaitKey(5) & 255) == 27 ) break;

        if(frame_count % 5 == 0) {
            LOGD("frame rate:%f", ((float) 5) / duration_stop() * 1000/*ms*/);
            duration_start();
        }
    }
    
    //cvDestroyWindow("window_0");
    cvDestroyWindow("window_1");
    cvReleaseCapture(&mCvCapture);
    return 0;
}