Example #1
0
Image CImageProcess::find(IplImage *in, Image *out)
{
	vector<vector<Location>> res;
	res.clear();
	//投影法,分割
	unsigned int *pVHist = new unsigned int[in->widthStep];
	VerticalProjection(in->imageData, in->widthStep, in->height, pVHist);
	unsigned int *pHHist = new unsigned int[in->height];
	HorizontalProjection(in->imageData, in->widthStep, in->height, pHHist);

	vector<Location> v_lc = Projection_Location(pVHist,in->widthStep, in->height);
	vector<Location> h_lc = Projection_Location(pHHist,in->height, in->widthStep);

	//切图
	Image image;
	image._height = in->height;
	image._width = in->widthStep;
	image._pData = new unsigned char[image._height * image._width];
	memset(image._pData, 0 , image._height * image._width);
	memcpy_s(image._pData, image._height * image._width, in->imageData, image._height * image._width);
	vector<Image> dst;
	CutImage(image, v_lc, h_lc, &dst);
	delete []image._pData;

	
	res.push_back(v_lc);
	res.push_back(h_lc);

	delete []pVHist;
	delete []pHHist;
	pVHist = nullptr;
	pHHist = nullptr;

	return dst.at(0);
}
Example #2
0
void CImageProcess::Sample(string path, float (*trainData)[MAX_TRAIN_COLS], int row)
{
	//test(path);
	IplImage*	pOSource = cvLoadImage(path.c_str());
	m_mapImage.insert(std::pair<string, IplImage*>(m_sName, pOSource));
	//opencv  灰度化
	IplImage* pOGray = cvCreateImage(cvGetSize(pOSource), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("gray", pOGray));
	cvCvtColor(pOSource, pOGray, CV_BGR2GRAY);
	//opencv 二值化
	IplImage*	pOBinary = cvCreateImage(cvGetSize(pOGray), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("binary", pOBinary));
	//cvThreshold(pOGray, pOBinary, 175, 255, CV_THRESH_BINARY_INV);
	ExcuteThreshold(pOGray, 175, true);

	vector<CvRect> rect = CheckBounds(pOGray);
	vector<IplImage*> image;
	CutImage(pOGray, rect, &image);

	vector<IplImage*>::iterator it = image.begin();
	for(int i=0; it != image.end(); it++,i++){
		InverseImage(*it);
	}

	vector<IplImage*> dst;
	ZoomImage_16(&image, &dst);

	it = image.begin();
	for(int i=0; it != image.end(); it++,i++){
			//char c[10]={0};
			//itoa(i,c,10);
			//cvNamedWindow(c,1); 
			//cvShowImage(c,*it);  
		cvReleaseImage(&(*it));
	}
	

	//ofstream fsave;
	//fsave.open("./sources/feature.txt", ios_base::out | ios_base::ate | ios_base::app);
	it=dst.begin();
	for(; it!=dst.end(); it++){
		ANN_ExtractFeature(*it , trainData, MAX_SAMPLES, MAX_TRAIN_COLS, row);
	//	ExtractFeature(*it, 1, 24, &fsave);
	}
	//fsave.close();

	//ANN_GetSample();
	//cvNamedWindow("二值图像",1);    
	//cvShowImage("二值图像",pOBinary);   
	//cvWaitKey(0);  
	//cvDestroyAllWindows();  
	//cvReleaseImage(&pOBinary);  
}
Example #3
0
void SetCard::Prosses(void)
{
    NormalizeColors();
    DetectAmount();
    mFound = (mContours.size() > 0);
    if (mFound)
    {
    	CutImage();
    	DetectShading();
    	DetectSymbol();
    	DetectColor();
    }

}
Example #4
0
void TImageWin::Notify(int result)
{
	if (result == IDRETRY) {
		::SetClassLong(hWnd, GCL_HCURSOR, (LONG)cursorMap[CROSS_ID]);
		status = INIT;
		InvalidateRect(NULL, FALSE);
		drawPts.clear();
	}
	else if (result == IDCANCEL || result == IDOK) {
		Show(SW_HIDE);
		parentWnd->Show();
		if (result == IDOK) {
			::SetFocus(parentWnd->GetDlgItem(SEND_EDIT));
			CutImage(useClip, withSave);
		}
		Destroy();
	}
}
Example #5
0
void CImageProcess::Sample(string path, float *obj, int cols)
{
	IplImage*	pOSource = cvLoadImage(path.c_str());
	m_mapImage.insert(std::pair<string, IplImage*>(m_sName, pOSource));
	//opencv  灰度化
	IplImage* pOGray = cvCreateImage(cvGetSize(pOSource), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("gray", pOGray));
	cvCvtColor(pOSource, pOGray, CV_BGR2GRAY);
	//opencv 二值化
	IplImage*	pOBinary = cvCreateImage(cvGetSize(pOGray), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("binary", pOBinary));
	//cvThreshold(pOGray, pOBinary, 175, 255, CV_THRESH_BINARY_INV);
	ExcuteThreshold(pOGray, 175, true);

	vector<CvRect> rect = CheckBounds(pOGray);
	vector<IplImage*> image;
	CutImage(pOGray, rect, &image);

	vector<IplImage*>::iterator it = image.begin();
	for(int i=0; it != image.end(); it++,i++){
		InverseImage(*it);
	}

	vector<IplImage*> dst;
	ZoomImage_16(&image, &dst);

	it = image.begin();
	for(int i=0; it != image.end(); it++,i++){
		//char c[10]={0};
		//itoa(i,c,10);
		//cvNamedWindow(c,1); 
		//cvShowImage(c,*it);  
		cvReleaseImage(&(*it));
	}


	//ofstream fsave;
	//fsave.open("./sources/feature.txt", ios_base::out | ios_base::ate | ios_base::app);
	it=dst.begin();
	if(it != dst.end()){
		ANN_ExtractFeature(*it , obj, cols);
	}
}
Example #6
0
int main(int argc, const char** argv) {
    po::variables_map vm;

    try {
        po::options_description desc("Allowed options");
        desc.add_options()
                ("help,?", "Show help message.")
                ("img,i", po::value<void>(), "Cut image.")
                ("video,v", po::value<std::string>(), "Cut image from specific time in video., Video Path")
                ("width,w", po::value<uint32_t>(), "Width of the object in the image.")
                ("height,h", po::value<uint32_t>(), "Height of the object in the image.")
                ("x", po::value<uint32_t>(), "X coordinate of the object in the image.")
                ("y", po::value<uint32_t>(), "Y coordinate of the object in the image.")
                ("time, t", po::value<double>(), "Y coordinate of the object in the image.")
                ("output,o", po::value<std::string>(), "Output file for the train data.");

        po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
        if (!vm["help"].empty()) {
            std::cout << desc;
        } else if (vm["y"].empty() && vm["height"].empty() &&
                   vm["x"].empty() && vm["width"].empty() &&
                   vm["output"].empty() && (vm["video"].empty() || vm["img"].empty())) {
            std::cout << "Please enter all the needed parameters" << std::endl;
        } else {
            if (!vm["img"].empty()) {
                CutImage(vm["img"].as<std::string>(), vm["x"].as<uint32_t>(),
                         vm["y"].as<uint32_t>(), vm["width"].as<uint32_t>(),
                         vm["height"].as<uint32_t>(), vm["output"].as<std::string>());
            } else if (!vm["video"].empty() && !vm["time"].empty()) {
                CutVideo(vm["video"].as<std::string>(), vm["x"].as<uint32_t>(),
                         vm["y"].as<uint32_t>(), vm["width"].as<uint32_t>(),
                         vm["height"].as<uint32_t>(), vm["time"].as<double>(),
                         vm["output"].as<std::string>());
            }
        }
    } catch (std::exception& e) {
        std::cout << "An error occurred: " << e.what() << std::endl;
    }
}
Example #7
0
/*
 * ImgEdFrameProc - handle messages for the image editor application
 */
WPI_MRESULT CALLBACK ImgEdFrameProc( HWND hwnd, WPI_MSG msg,
                                 WPI_PARAM1 wparam, WPI_PARAM2 lparam )
{
    static BOOL         window_destroyed = FALSE;
    static HMENU        hmenu;
    ctl_id              cmdid;
    img_node            *node;
    WPI_RECT            rcmain;
#ifndef __OS2_PM__
    about_info          ai;
#endif
    WPI_RECTDIM         left, top;

    if( !window_destroyed ) {
        enableMainItems( hmenu );
    }

    switch( msg ) {
    case UM_EXIT:
        _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L );
        /* fall through */

    case UM_EXIT_NO_SAVE:
        if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) {
            break;
        }
#ifndef __OS2_PM__
        _wpi_destroywindow( _wpi_getframe( hwnd ) );
#else
        _wpi_sendmessage( hwnd, WM_CLOSE, 0, 0 );
#endif

        break;

    case UM_SAVE_ALL:
        SaveAllImages();
        break;

    case WM_CREATE:
        hmenu = _wpi_getmenu( _wpi_getframe( hwnd ) );
#ifndef __OS2_PM__
        createClientWindow( hwnd );
#endif
        if( !InitStatusLine( hwnd ) ) {
            return( -1 );
        }

        InitFunctionBar( hwnd );
        InitIconInfo();
        InitializeCursors();

        /*
         * Set values from profile information ...
         */
        if( ImgedConfigInfo.brush_size <= 5 && ImgedConfigInfo.brush_size >= 2 ) {
            checkBrushItem( hmenu, IMGED_2x2 - 2 + ImgedConfigInfo.brush_size );
        }
        if( ImgedConfigInfo.grid_on ) {
            CheckGridItem( hmenu );
        }
        if( ImgedConfigInfo.square_grid ) {
            CheckSquareGrid( hmenu );
        }
        if( ImgedConfigInfo.show_state & SET_SHOW_VIEW ) {
            CheckViewItem( hmenu );
        }

        _wpi_enablemenuitem( hmenu, IMGED_CRESET, FALSE, FALSE );
        _wpi_enablemenuitem( hmenu, IMGED_RCOLOR, FALSE, FALSE );
#ifndef __OS2_PM__
        // not necessary for PM
        InitMenus( hmenu );
#endif
        SetHintText( IEAppTitle );
        return( 0 );
#ifdef __NT__
    case WM_DROPFILES:
        OpenImage( (HANDLE)wparam );
        break;
#endif
    case WM_MOVE:
        _wpi_getwindowrect( hwnd, &rcmain );
        if( !ImgedConfigInfo.ismaximized ) {
            ImgedConfigInfo.last_xpos = ImgedConfigInfo.x_pos;
            ImgedConfigInfo.last_ypos = ImgedConfigInfo.y_pos;
            _wpi_getrectvalues( rcmain, &left, &top, NULL, NULL );
            ImgedConfigInfo.x_pos = (short)left;
            ImgedConfigInfo.y_pos = (short)top;
        }
        return( 0 );

    case WM_SIZE:
        ResizeFunctionBar( lparam );
        ResizeStatusBar( lparam );
#ifndef __OS2_PM__
        if( ClientWindow != NULL ) {
            setClientSize( hwnd );
        }
#else
        resizeClientArea( lparam );
#endif

        if( !_imgwpi_issizeminimized( wparam ) && !_imgwpi_issizemaximized( wparam ) ) {
            _wpi_getwindowrect( hwnd, &rcmain );
            ImgedConfigInfo.width = (short)_wpi_getwidthrect( rcmain );
            ImgedConfigInfo.height = (short)_wpi_getheightrect( rcmain );
            ImgedConfigInfo.ismaximized = FALSE;
        } else {
            ImgedConfigInfo.x_pos = ImgedConfigInfo.last_xpos;
            ImgedConfigInfo.y_pos = ImgedConfigInfo.last_ypos;
            ImgedConfigInfo.ismaximized = _imgwpi_issizemaximized( wparam );
        }
        return( FALSE );

    case WM_MENUSELECT:
#ifndef __OS2_PM__
        if( GET_WM_MENUSELECT_FLAGS( wparam, lparam ) & MF_SEPARATOR ) {
            break;
        }
        if( GET_WM_MENUSELECT_FLAGS( wparam, lparam ) & MF_SYSMENU ) {
            PrintHintTextByID( WIE_SYSMENUOPERATIONS, NULL );
            break;
        }
#endif
        ShowHintText( LOWORD( wparam ) );
        break;

    case WM_COMMAND:
        cmdid = LOWORD( wparam );
        if( !IEIsMenuIDValid( hmenu, cmdid ) ) {
            break;
        }
        switch( cmdid ) {
        case IMGED_NEW:
            if( !ImgedIsDDE ) {
                if( !NewImage( UNDEF_IMG, NULL ) ) {
                    PrintHintTextByID( WIE_NEIMAGENOTCREATED, NULL );
                }
            }
            break;

        case IMGED_CLOSE:
            node = GetCurrentNode();
            if( node != NULL ) {
                _wpi_sendmessage( node->hwnd, WM_CLOSE, 0, 0L );
            }
            break;

        case IMGED_CLOSEALL:
            CloseAllImages();
            break;

        case IMGED_HELP:
            IEHelpRoutine();
            break;

        case IMGED_HELP_SEARCH:
            IEHelpSearchRoutine();
            break;

        case IMGED_HELP_ON_HELP:
            IEHelpOnHelpRoutine();
            break;

        case IMGED_ABOUT:
#ifndef __OS2_PM__
            ai.owner = hwnd;
            ai.inst = Instance;
            ai.name = IEAllocRCString( WIE_ABOUTTEXT );
            ai.version = IEAllocRCString( WIE_ABOUTVERSION );
            ai.title = IEAllocRCString( WIE_ABOUTTITLE );
            DoAbout( &ai );
            if( ai.name != NULL ) {
                IEFreeRCString( ai.name );
            }
            if( ai.version != NULL ) {
                IEFreeRCString( ai.version );
            }
            if( ai.title != NULL ) {
                IEFreeRCString( ai.title );
            }
#endif
            break;

#ifndef __OS2_PM__
        case IMGED_DDE_UPDATE_PRJ:
            IEUpdateDDEEditSession();
            break;
#endif

        case IMGED_SAVE_AS:
            SaveFile( SB_SAVE_AS );
            break;

        case IMGED_SAVE:
            SaveFile( SB_SAVE );
            break;

        case IMGED_OPEN:
            if( !ImgedIsDDE ) {
                OpenImage( NULL );
            }
            break;

        case IMGED_CLEAR:
            ClearImage();
            break;

        case IMGED_NEWIMG:
            AddNewIcon();
            break;

        case IMGED_SELIMG:
            SelectIconImg();
            break;

        case IMGED_DELIMG:
            DeleteIconImg();
            break;

        case IMGED_UNDO:
            UndoOp();
            break;

        case IMGED_REDO:
            RedoOp();
            break;

        case IMGED_REST:
            RestoreImage();
            break;

        case IMGED_SNAP:
#ifndef __OS2_PM__
            SnapPicture();
#endif
            break;

        case IMGED_RIGHT:
        case IMGED_LEFT:
        case IMGED_UP:
        case IMGED_DOWN:
            ShiftImage( cmdid );
            break;

        case IMGED_FLIPHORZ:
        case IMGED_FLIPVERT:
            FlipImage( cmdid );
            break;

        case IMGED_ROTATECC:
        case IMGED_ROTATECL:
            RotateImage( cmdid );
            break;

        case IMGED_PASTE:
            PlaceAndPaste();
            break;

        case IMGED_COPY:
            IECopyImage();
            break;

        case IMGED_CUT:
            CutImage();
            break;

        case IMGED_COLOR:
            CheckPaletteItem( hmenu );
            break;

        case IMGED_VIEW:
            CheckViewItem( hmenu );
            break;

        case IMGED_TOOLBAR:
            CheckToolbarItem( hmenu );
            break;

        case IMGED_SQUARE:
            CheckSquareGrid( hmenu );
            break;

        case IMGED_SIZE:
            ChangeImageSize();
            break;

        case IMGED_GRID:
            CheckGridItem( hmenu );
            break;

        case IMGED_MAXIMIZE:
            MaximizeCurrentChild();
            break;

        case IMGED_SETTINGS:
            SelectOptions();
            break;

        case IMGED_2x2:
        case IMGED_3x3:
        case IMGED_4x4:
        case IMGED_5x5:
            checkBrushItem( hmenu, cmdid );
            break;

        case IMGED_CEDIT:
#ifndef __OS2_PM__
            EditColors();
#endif
            break;

        case IMGED_CRESET:
#ifndef __OS2_PM__
            RestoreColors();
#endif
            break;

        case IMGED_CSCREEN:
            ChooseBkColor();
            break;

        case IMGED_SCOLOR:
#ifndef __OS2_PM__
            SaveColorPalette();
#endif
            break;

        case IMGED_LCOLOR:
#ifndef __OS2_PM__
            if( LoadColorPalette() ) {
                _wpi_enablemenuitem( hmenu, IMGED_RCOLOR, TRUE, FALSE );
            }
#endif
            break;

        case IMGED_RCOLOR:
            RestoreColorPalette();
            break;

        case IMGED_FREEHAND:
        case IMGED_LINE:
        case IMGED_RECTO:
        case IMGED_RECTF:
        case IMGED_CIRCLEO:
        case IMGED_CIRCLEF:
        case IMGED_FILL:
        case IMGED_BRUSH:
        case IMGED_CLIP:
        case IMGED_HOTSPOT:
            SetToolType( cmdid );
            PushToolButton( cmdid );
            break;

        case IMGED_ARRANGE:
#ifndef __OS2_PM__
            SendMessage( ClientWindow, WM_MDIICONARRANGE, 0, 0L );
#endif
            break;

        case IMGED_TILE:
#ifndef __OS2_PM__
            SendMessage( ClientWindow, WM_MDITILE, MDITILE_VERTICAL, 0L );
#endif
            break;

        case IMGED_CASCADE:
#ifndef __OS2_PM__
            SendMessage( ClientWindow, WM_MDICASCADE, MDITILE_SKIPDISABLED, 0L );
#endif
            break;

        case IMGED_EXIT:
            _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L );

            if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) {
                break;
            }
#ifndef __OS2_PM__
            _wpi_destroywindow( _wpi_getframe( hwnd ) );
#else
            _wpi_sendmessage( hwnd, WM_CLOSE, 0, 0 );
#endif
            break;

        default:
#if 1
            return( _imgwpi_defframeproc( hwnd, ClientWindow, msg, wparam, lparam ) );
#else
            return( 0 );
#endif
        }
        return( 0 );

#ifndef __OS2_PM__
    case WM_COMPACTING:
        RelieveUndos();
        return 0;
#endif

    case WM_QUERYENDSESSION:
        if( _wpi_isiconic( _wpi_getframe( hwnd ) ) ) {
            if( ImgedConfigInfo.ismaximized ) {
                _wpi_maximizewindow( _wpi_getframe( hwnd ) );
            } else {
                _wpi_showwindow( _wpi_getframe( hwnd ), SW_SHOWNORMAL );
            }
        }
        _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L );

        if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) {
            return( 0 );
        }
        return( (WPI_MRESULT)1 );

    case WM_CLOSE:
        // wParam is non-zero if the DDE connection died
        if( !wparam && !ImgEdEnableMenuInput ) {
            // this prevents the user from closing the editor during
            // DDE initialization
            return( 0 );
        }
        _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L );
#ifdef __OS2_PM__
        return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
#else

        if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) {
            return( 0 );
        }
        window_destroyed = TRUE;
        _wpi_destroywindow( _wpi_getframe( hwnd ) );
        return( 0 );
#endif

    case WM_DESTROY:
#ifndef __OS2_PM__
        WWinHelp( HMainWindow, "resimg.hlp", HELP_QUIT, 0 );
#endif
        FiniStatusLine();
        CleanupClipboard();
        CleanupCursors();
        CloseToolBar();
        CloseFunctionBar();
        _wpi_deletefont( SmallFont );
        _wpi_postquitmessage( 0 );
        return( 0 );
    default:
        break;
    }
    return( _imgwpi_defframeproc( hwnd, ClientWindow, msg, wparam, lparam ) );

} /* ImgEdFrameProc */
Example #8
0
void CImageProcess::ProcessImage()
{
	IplImage*	pOSource = cvLoadImage(m_sName.c_str());
	m_mapImage.insert(std::pair<string, IplImage*>(m_sName, pOSource));
	//opencv  灰度化
	IplImage* pOGray = cvCreateImage(cvGetSize(pOSource), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("gray", pOGray));

	cvCvtColor(pOSource, pOGray, CV_BGR2GRAY);

	//opencv 二值化
	IplImage*	pOBinary = cvCreateImage(cvGetSize(pOGray), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("binary", pOBinary));
	cvThreshold(pOGray, pOBinary, 175, 255, CV_THRESH_BINARY);

	//pSwellTemp = LevelSwell(pOBinary->imageData, pOBinary->widthStep, pOBinary->height,8);
	//VerticalSwell(pOBinary->imageData, pOBinary->widthStep, pOBinary->height, 0);
	//OpencvSwell(pOBinary, pOBinary);

	//投影法,分割
	unsigned int *pVHist = new unsigned int[pOBinary->widthStep];
	VerticalProjection(pOBinary->imageData, pOBinary->widthStep, pOBinary->height, pVHist);
	unsigned int *pHHist = new unsigned int[pOBinary->height];
	HorizontalProjection(pOBinary->imageData, pOBinary->widthStep, pOBinary->height, pHHist);

	vector<Location> v_lc = Projection_Location(pVHist,pOBinary->widthStep, pOBinary->height);
	vector<Location> h_lc = Projection_Location(pHHist,pOBinary->height, pOBinary->widthStep);

	//切图
	Image image;
	image._height = pOBinary->height;
	image._width = pOBinary->widthStep;
	image._pData = new unsigned char[image._height * image._width];
	memset(image._pData, 0 , image._height * image._width);
	memcpy_s(image._pData, image._height * image._width, pOBinary->imageData, image._height * image._width);
	vector<Image> dst;
	CutImage(image, v_lc, h_lc, &dst);
	delete []image._pData;

	//缩放
	//Location l = FindMaxLocation(v_lc, h_lc);
	Location l;
	l._start = 16;
	l._end = 16;
	vector<Image> zImage;
	ZoomImage(&dst,&zImage, l);

	//提取特征
	for(int i=0; i<zImage.size(); i++){
		char c[10];
		itoa(i, c, 10);
		IplImage *img = CreateImage(zImage.at(i));
		//m_mapImage.insert(std::pair<string, IplImage*>(c, img));
		SIFTInstance(img, c);
		ReleaseUserImage(&img);
	}
	
/*
	char*		cOTitle = {"opencv"};
	cvNamedWindow(cOTitle, CV_WINDOW_AUTOSIZE);
	cvShowImage(cOTitle,pOBinary);*/

	//test();
	cvWaitKey();

	cvDestroyAllWindows();
}