示例#1
0
/******************************************************\
 * Description:	construct a scroll bar that is used   *
 *		for scrolling through the hex editor  *
\******************************************************/ 
void scrollbar(WINS *windows,  int cl, long maxLines)
{
    float x, percent;

    /* Avoid unused variable warning */
    UNUSED(maxLines);
    
    /* cl really should be a long, it wasn't changed because cl is used
     * in other functions as an int.  Eventually everything should be using
     * long rather than int */

    if (fpIN != NULL)
	percent = (float)cl/(float)maxLoc(fpIN);	/* protect against x/0*/
    else
	percent = 0.0;

    x = (int)(percent * (float)(LINES));
    x = (x < 1) ? 1 : x;
    x = (x >= (LINES - 1)) ? LINES - 2 : x;

    wattron(windows->scrollbar, A_REVERSE);		/* set attribs on bar */
    wattron(windows->scrollbar, A_REVERSE);		/* set attribs on bar */
    mvwaddch(windows->scrollbar, (int)x, 0, ACS_DIAMOND);
    wattroff(windows->scrollbar, A_REVERSE);
    wnoutrefresh(windows->scrollbar);			/* refresh the bar    */
    mvwaddch(windows->scrollbar, (int)x, 0, ACS_CKBOARD);
}
int PathDetect::FloodArea(cv::Mat& watershedImage, cv::Point& startPoint, unsigned char id) const
{
    const int floodX[4]={1,-1,0,0};
    const int floodY[4]={0,0,1,-1};
    cv::Point maxLoc(watershedImage.cols, watershedImage.rows);

    std::vector<cv::Point> stack;
    int pixelCount = 1;
    stack.push_back(startPoint);
    watershedImage.at<unsigned char>(startPoint) = id;
    while (stack.size() > 0)
    {
        cv::Point currentLocation = stack.back();
        stack.pop_back();
        int x = currentLocation.x;
        int y = currentLocation.y;
        for (int i=0; i<4; ++i)
        {
            int possibleX = x+floodX[i];
            int possibleY = y+floodY[i];
            cv::Point newLoc(possibleX, possibleY);
            if (ValidForFloodFill(newLoc, maxLoc) && watershedImage.at<unsigned char>(newLoc) == PATH)
            {
                stack.push_back(newLoc);
                watershedImage.at<unsigned char>(newLoc) = id;
                pixelCount += 1;
            }
        }
    }
    return pixelCount;
}
示例#3
0
/********************************************************\
 * Description: parses command line arguments and 	*
 *		processes them.				*
 * Returns:	length of file				*
\********************************************************/
off_t parseArgs(int argc, char *argv[])
{
    extern char *optarg;				/* extern vars for    */
    extern int optind, /*opterr,*/ optopt;		/* getopt()	      */

    int val;						/* counters, etc.     */

							/* get args           */
    while ((val = hgetopt(argc, argv, "a:i:o:r:e")) != -1) 
    {
	switch (val)					/* test args          */
        {
            case 'a':	printHex = FALSE;		/* decimal addresses  */
                        break;
							/* infile             */
	    case 'i':	free(fpINfilename);
			fpINfilename = strdup(optarg);
			break;
							/* outfile            */
	    case 'o':   free(fpOUTfilename);
			fpOUTfilename = strdup(optarg);
			break;

            case 'r':   resize = atoi(optarg);		/* don't resize screen*/
                        break;

            case 'e':   USE_EBCDIC=TRUE;		/*use instead of ascii*/
                        break;
							/* help/invalid args  */
							/* help/invalid args  */
	    case '?':	print_usage();			/* output help        */
                        if ((optopt == 'h') || (optopt == '?'))
			    exit(0);			/* exit               */
			else				/* illegal option     */
			    exit(-1);
        }
    }
    argc -= optind;
    argv += optind;

    if (argv[0])
    {
	free(fpINfilename);
        fpINfilename = strdup(argv[0]);
    }

    if (fpINfilename && strcmp(fpINfilename, ""))
        if ((fpIN = fopen(fpINfilename, "r")) == NULL)
            exit_err("Could not open file");

    return ((fpIN != NULL) ? maxLoc(fpIN):0);		/* return file length */
}
void ras_cv::normalise(cv::Mat& img, cv::Mat& normimg){
	double minVal = 0;
	double maxVal = 0;
	cv::Point2i minLoc(0, 0);
	cv::Point2i maxLoc(0, 0);

	// cvMat normimg;
	img.convertTo(normimg, CV_32F);
	cv::minMaxLoc(normimg, &minVal, &maxVal, &minLoc, &maxLoc);
	normimg = normimg / maxVal;
	// img = normimg;

}
示例#5
0
    void minMaxLocGold(const Mat& src, double* minVal_, double* maxVal_, Point* minLoc_, Point* maxLoc_, const Mat& mask)
    {
        if (src.depth() != CV_8S)
        {
            minMaxLoc(src, minVal_, maxVal_, minLoc_, maxLoc_, mask);
            return;
        }

        // OpenCV's minMaxLoc doesn't support CV_8S type
        double minVal = std::numeric_limits<double>::max();
        Point minLoc(-1, -1);

        double maxVal = -std::numeric_limits<double>::max();
        Point maxLoc(-1, -1);

        for (int y = 0; y < src.rows; ++y)
        {
            const schar* src_row = src.ptr<schar>(y);
            const uchar* mask_row = mask.empty() ? 0 : mask.ptr<uchar>(y);

            for (int x = 0; x < src.cols; ++x)
            {
                if (!mask_row || mask_row[x])
                {
                    schar val = src_row[x];

                    if (val < minVal)
                    {
                        minVal = val;
                        minLoc = cv::Point(x, y);
                    }

                    if (val > maxVal)
                    {
                        maxVal = val;
                        maxLoc = cv::Point(x, y);
                    }
                }
            }
        }

        if (minVal_) *minVal_ = minVal;
        if (maxVal_) *maxVal_ = maxVal;

        if (minLoc_) *minLoc_ = minLoc;
        if (maxLoc_) *maxLoc_ = maxLoc;
    }
示例#6
0
int main(int argc, char *argv[])			/* main program       */
{

    int   x, retval = 1;			/* counters, etc.     */
    off_t val, len;					/* len need to be off_t*/

    windows = (WINS *) calloc(1, sizeof(WINS));	/* malloc windows     */
    head = llalloc();							/* malloc list space  */
    fpINfilename = NULL;			/* allocate in and    */
    fpOUTfilename = NULL;			/* out file name ptrs */
    printHex = TRUE;							/* address format     */
    USE_EBCDIC = FALSE;							/*use ascii by default*/

							/* get cmd line args  */
    len = parseArgs(argc, argv);
    MIN_ADDR_LENGTH = getMinimumAddressLength(len);

    use_env(TRUE);					/* use env values     */
    slk_init(0);					/* init menu bar      */
    init_screen();					/* init visuals       */
    init_colors();

    if ((COLS < MIN_COLS) || (LINES < MIN_LINES))	/* screen's too small */
    {
	endwin();
	fprintf(stderr,"\n\nThe screen size too small.\nThe minimum allowable");
	fprintf(stderr," screen size is %dx%d\n\n", MIN_COLS, MIN_LINES + 1);
	exit(-1);
    }
    
    slk_set(6, (printHex) ? "Hex Addr":"Dec Addr", 1);
    init_fkeys();					/* define menu bar    */
    

    while (retval)
    {
	free_windows(windows);
        
	/* calculate screen   */
	BASE                = (resize > 0 && resize < COLS) ? resize:((COLS-6-MIN_ADDR_LENGTH)/4);
	MAXY                = (LINES) - 3;
	hex_win_width       = BASE * 3;
	ascii_win_width     = BASE;
	hex_outline_width   = (BASE * 3) + 3 + MIN_ADDR_LENGTH;
	ascii_outline_width = BASE + 2;
            
	init_menu(windows);				/* init windows       */
	head = freeList(head);				/* free & init head   */
							/* print origin loc   */
	mvwprintw(windows->hex_outline, 0, 1, "%0*d", MIN_ADDR_LENGTH, 0);
    
	if (fpIN != NULL)				/* if no infile...    */
	{
            len = maxLoc(fpIN);				/* get last file loc  */
	    val = maxLines(len); 			/* max file lines     */
            for (x = 0; x <= MAXY && x<=val; x++)       /* output lines       */
		outline(fpIN, x);
	}

	wmove(windows->hex, 0, 0);			/* cursor to origin   */
    
	refreshall(windows);				/* refresh all wins   */
	doupdate();					/* update screen      */
        
	mvwaddch(windows->scrollbar, 1, 0, ACS_CKBOARD);/* clear scroller     */
							/* get user input     */
	retval = wacceptch(windows, len); 
    }
    
    free(fpINfilename);
    free(fpOUTfilename);
    freeList(head);
    
    screen_exit(0);					/* end visualizations */
    return retval;					/* return             */
}
示例#7
0
/******************************************************\
 * Description:	Determines the screen size of the the *
 *		terminal and prompts for the user to  *
 *		change the screen.		      *
\******************************************************/
RETSIGTYPE checkScreenSize(int sig)
{   
    int count;
    
    /* Avoid unused variable warning */
    UNUSED(sig);

    clearScreen(windows);
    endwin();
    init_screen();                                      /* init visuals       */

    slk_clear();                                        /* init menu bar      */
    slk_restore();                                      /* restore bottom menu*/
    slk_noutrefresh();
    doupdate();
							/* recacl these values*/
    BASE                =   (COLS - 6 - MIN_ADDR_LENGTH) / 4;            /*base for the number */
    hex_outline_width   =   (BASE * 3) + 3 + MIN_ADDR_LENGTH;
    MAXY                =   LINES - 3;
    hex_win_width       =   BASE * 3;
    ascii_outline_width =   BASE + 2;
    ascii_win_width     =   BASE;
    maxlines		=   maxLines((fpIN != NULL) ? maxLoc(fpIN) : 0);
    currentLine		=   0;
    SIZE_CH		=   TRUE;
                                                        /* check for term size*/
    if ((COLS < MIN_COLS) || (LINES < MIN_LINES))	
    {    
	/*
        endwin();
        printf("\n\n\n\nscreen size too small\n");
        exit(0);
	*/

	init_fkeys();                                   /* define menu bar    */
	init_menu(windows);                             /* init windows       */
	clearScreen(windows);
	slk_clear();
	mvwprintw(windows->hex, 0, 0, "Your screen is too small");
	/*mvwprintw(windows->hex, 1, 2, "Resize it to continue");*/
	refreshall(windows);
	doupdate();
    }
    else
    {
	init_fkeys();                                   /* define menu bar    */
	init_menu(windows);                             /* init windows       */
	wmove(windows->hex,0,0);
	if (fpIN)					/* if a file is open  */
	{
	    for (count = 0; count <= MAXY && count <= maxLines(maxLoc(fpIN)); 
		 count++)
		outline(fpIN, count);

	    mvwprintw(windows->cur_address, 0, 0, "%0*d", MIN_ADDR_LENGTH, 0);
	    wmove(windows->hex,0,0);
	}

	refreshall(windows);
        wnoutrefresh(windows->cur_address);
	/* this next refresh is to put the cursor in the correct window */
        wnoutrefresh(windows->hex);
	doupdate();
    }
}