コード例 #1
0
void EdgeDetectorCanny::apply(cv::InputArray _oInputImage, cv::OutputArray _oEdgeMask) {
    cv::Mat oInputImg = _oInputImage.getMat();
    CV_Assert(!oInputImg.empty());
    CV_Assert(oInputImg.channels()==1 || oInputImg.channels()==3 || oInputImg.channels()==4);
    _oEdgeMask.create(oInputImg.size(),CV_8UC1);
    cv::Mat oEdgeMask = _oEdgeMask.getMat();
    oEdgeMask = cv::Scalar_<uchar>(0);
    cv::Mat oTempEdgeMask = oEdgeMask.clone();
    for(size_t nCurrThreshold=0; nCurrThreshold<UCHAR_MAX; ++nCurrThreshold) {
        apply_threshold(oInputImg,oTempEdgeMask,double(nCurrThreshold));
        oEdgeMask += oTempEdgeMask/UCHAR_MAX;
    }
    cv::normalize(oEdgeMask,oEdgeMask,0,UCHAR_MAX,cv::NORM_MINMAX);
}
コード例 #2
0
ファイル: markers.cpp プロジェクト: kenkeiter/interface
/* Fetch a frame (if available) and process it, calling appropriate 
 callbacks when data becomes available. */
void MarkerCapture::tick(){
    IplImage *thresh_frame = NULL;
    CBlobResult blobs;
    
    // Acquire the lock, update the current frame.
    pthread_mutex_lock(&frame_mutex);
    current_frame = cvCloneImage(cvQueryFrame(camera));
    if(color_acquired && current_frame){
        thresh_frame = apply_threshold(current_frame, target_color);
    }else{
        // create a suplicant.
        thresh_frame = cvCreateImage(cvGetSize(current_frame),IPL_DEPTH_8U,1);
    }
    pthread_mutex_unlock(&frame_mutex);
    // Lock released. Done messing with buffers.
    
    if(frame_update_callback){
        (*frame_update_callback)(this, current_frame, thresh_frame);
    }
    if(color_acquired){
        blobs = detect_blobs(thresh_frame, CV_BLOB_SIZE_MIN);
        if(blobs.GetNumBlobs() >= 2){ // need 2 or more blobs for positional fix.
            MarkerPositionEstimate position;
            // fetch the two largest blobs, by area.
            CBlob blob0, blob1;
            blobs.GetNthBlob(CBlobGetArea(), 0, blob0);
            blobs.GetNthBlob(CBlobGetArea(), 1, blob1);
            // perform positional calculations
            position.distance = distance(blob0, blob1);
            position.angle = angle(blob0, blob1);
            position.blob0_center = blob_center(blob0);
            position.blob1_center = blob_center(blob1);
            // call the update handler.
            if(position_update_callback){
                (*position_update_callback)(this, position);
            }
        }
        blobs.ClearBlobs();
    }
    
    pthread_mutex_lock(&frame_mutex);
    cvReleaseImage(&current_frame);
    cvReleaseImage(&thresh_frame);
    pthread_mutex_unlock(&frame_mutex);
    
    int curr_time = clock();
    fps = CLOCKS_PER_SEC/(double)(curr_time - time);
    time = curr_time;
}
コード例 #3
0
void test_otsu_step(){
	//IplImage * edge_image = min_max_edge_detection(image);
	//display_image("edge_image",edge_image);
	IplImage * edge_image = cvLoadImage("images/edges.png",0);
	display_image("edges image",edge_image);
	IplImage * otsu_image = otsu_algorithm(edge_image);
	otsu_image = invert_image(otsu_image);
	display_image("otsu image",otsu_image);
	IplImage * segmented_pixels = get_pixels_on_template(image,otsu_image);
	display_image("segmented pixs",segmented_pixels);
	int threshold = otsu_thresholding_no_white(segmented_pixels);
	IplImage* fimage = apply_threshold(segmented_pixels,threshold);
	display_image("fimage", fimage);
	cvSaveImage("images/otsu_edges.png",otsu_image);

	
}
コード例 #4
0
ファイル: ob_threshold.cpp プロジェクト: ChrisVeigl/BrainBay
LRESULT CALLBACK ThresholdDlgHandler( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	static int init;
	char temp[100];
	THRESHOLDOBJ * st;
	int x;
	
	st = (THRESHOLDOBJ *) actobject;
    if ((st==NULL)||(st->type!=OB_THRESHOLD)) return(FALSE);

	for (x=0;x<GLOBAL.objects;x++) if (objects[x]==actobject) 
	{ char tmp[10]; wsprintf(tmp,"%d",x); 
	  //SendDlgItemMessage(ghWndStatusbox,IDC_LISTE,LB_ADDSTRING, 0, (LPARAM)(tmp)); 
	}
					

	switch( message )
	{
		case WM_INITDIALOG:
			{
				SCROLLINFO lpsi;
				
				
				lpsi.cbSize=sizeof(SCROLLINFO);
				lpsi.fMask=SIF_RANGE; // |SIF_POS;
				
				lpsi.nMin=1; lpsi.nMax=1000;
				SetScrollInfo(GetDlgItem(hDlg,IDC_AVGINTERVALBAR),SB_CTL,&lpsi,TRUE);
				SetScrollInfo(GetDlgItem(hDlg,IDC_ADAPTINTERVALBAR),SB_CTL,&lpsi,TRUE);

				lpsi.nMin=-1000; lpsi.nMax=1000;
				SetScrollInfo(GetDlgItem(hDlg,IDC_AVGGAINBAR),SB_CTL,&lpsi,TRUE);

				lpsi.nMin=0; lpsi.nMax=1000;
				SetScrollInfo(GetDlgItem(hDlg,IDC_AVGFROMBAR),SB_CTL,&lpsi,TRUE);
				SetScrollInfo(GetDlgItem(hDlg,IDC_AVGTOBAR),SB_CTL,&lpsi,TRUE);

				lpsi.nMin=0; lpsi.nMax=100;
				SetScrollInfo(GetDlgItem(hDlg,IDC_BARSIZEBAR),SB_CTL,&lpsi,TRUE);
				SetScrollInfo(GetDlgItem(hDlg,IDC_FONTSIZEBAR),SB_CTL,&lpsi,TRUE);

				init=TRUE;
				SetDlgItemInt(hDlg, IDC_AVGINTERVAL, st->interval_len,TRUE);
				SetDlgItemInt(hDlg, IDC_ADAPTINTERVAL, st->adapt_interval,TRUE);
				SetScrollPos(GetDlgItem(hDlg,IDC_AVGINTERVALBAR), SB_CTL,st->interval_len,TRUE);
				SetScrollPos(GetDlgItem(hDlg,IDC_ADAPTINTERVALBAR), SB_CTL,st->adapt_interval,TRUE);

				SetDlgItemInt(hDlg, IDC_AVGGAIN, st->signal_gain,1);
				SetScrollPos(GetDlgItem(hDlg,IDC_AVGGAINBAR), SB_CTL,st->signal_gain,TRUE);

				SetDlgItemInt(hDlg, IDC_BARSIZE, st->barsize,0);
				SetScrollPos(GetDlgItem(hDlg,IDC_BARSIZEBAR), SB_CTL,st->barsize,TRUE);
				SetDlgItemInt(hDlg, IDC_FONTSIZE, st->fontsize,0);
				SetScrollPos(GetDlgItem(hDlg,IDC_FONTSIZEBAR), SB_CTL,st->fontsize,TRUE);

				sprintf(temp,"%.2f",st->from_input);
				SetDlgItemText(hDlg, IDC_AVGFROM, temp);
				SetScrollPos(GetDlgItem(hDlg,IDC_AVGFROMBAR), SB_CTL,(int) size_value(st->in_ports[0].in_min,st->in_ports[0].in_max, st->from_input ,0.0f,1000.0f,0),TRUE);

				sprintf(temp,"%.2f",st->to_input);
				SetDlgItemText(hDlg, IDC_AVGTO, temp);
				SetScrollPos(GetDlgItem(hDlg,IDC_AVGTOBAR), SB_CTL,(int) size_value(st->in_ports[0].in_min,st->in_ports[0].in_max, st->to_input ,0.0f,1000.0f,0),TRUE);

				SetDlgItemInt(hDlg, IDC_BIGADAPT, st->bigadapt,TRUE);
				SetDlgItemInt(hDlg, IDC_SMALLADAPT, st->smalladapt,TRUE);

				SetDlgItemText(hDlg, IDC_METERCAPTION, st->wndcaption);

				CheckDlgButton(hDlg, IDC_AND,st->op);
				CheckDlgButton(hDlg, IDC_OR,!st->op);
				CheckDlgButton(hDlg, IDC_SHOWMETER,st->showmeter);
				CheckDlgButton(hDlg, IDC_RISING,st->rising);
				CheckDlgButton(hDlg, IDC_FALLING,st->falling);
				CheckDlgButton(hDlg, IDC_USE_MEDIAN,st->usemedian);
				CheckDlgButton(hDlg, IDC_BASELINE,st->baseline);
				if (st->baseline) SetDlgItemText(hDlg,IDC_INTERVALUNIT,"Seconds");
				else SetDlgItemText(hDlg,IDC_INTERVALUNIT,"Samples");

				init=FALSE;
			}
			return TRUE;
	
		case WM_CLOSE:
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			break;
		case WM_COMMAND:
			switch (LOWORD(wParam)) 
			{
			case IDC_AND: st->op=TRUE; break;
			case IDC_OR:  st->op=FALSE; break;
			case IDC_RISING: st->rising=IsDlgButtonChecked(hDlg,IDC_RISING); break;
			case IDC_FALLING: st->falling=IsDlgButtonChecked(hDlg,IDC_FALLING); break;
			case IDC_USE_MEDIAN: st->usemedian=IsDlgButtonChecked(hDlg,IDC_USE_MEDIAN); break;
			case IDC_BASELINE: st->baseline=IsDlgButtonChecked(hDlg,IDC_BASELINE); 
				if (st->baseline) SetDlgItemText(hDlg,IDC_INTERVALUNIT,"Seconds");
				else SetDlgItemText(hDlg,IDC_INTERVALUNIT,"Samples");
				break;
			case IDC_SELECTCOLOR:
				st->color=select_color(hDlg,st->color);
				st->redraw=1;
				InvalidateRect(hDlg,NULL,FALSE);
				break;
			case IDC_BKCOLOR:
				st->bkcolor=select_color(hDlg,st->bkcolor);
				st->redraw=1;
				InvalidateRect(hDlg,NULL,FALSE);
				break;
			case IDC_FONTCOL:
				st->fontcolor=select_color(hDlg,st->fontcolor);
				st->redraw=1;
				InvalidateRect(hDlg,NULL,FALSE);
				break;
			case IDC_FONTBKCOL:
				st->fontbkcolor=select_color(hDlg,st->fontbkcolor);
				st->redraw=1;
				InvalidateRect(hDlg,NULL,FALSE);
				break;

			case IDC_AVGFROM:
				GetDlgItemText(hDlg, IDC_AVGFROM,temp,sizeof(temp));
				if (!init)	
					 st->from_input=(float)atof(temp);
				break;
			case IDC_AVGTO:
				GetDlgItemText(hDlg, IDC_AVGTO,temp,sizeof(temp));
				if (!init) 
					st->to_input=(float)atof(temp);
				break;
			case IDC_AVGINTERVAL:
			case IDC_ADAPTINTERVAL:
			case IDC_AVGGAIN:
			case IDC_BIGADAPT:
			case IDC_SMALLADAPT:
			case IDC_METERCAPTION:
				 if (!init) 
					 apply_threshold(hDlg, st);
					break;

			
			case IDC_SHOWMETER:
				{  int i;
				   i=IsDlgButtonChecked(hDlg,IDC_SHOWMETER);
				   if ((st->showmeter)&&(!i)&&(st->displayWnd))  { DestroyWindow(st->displayWnd); st->displayWnd=NULL; }
				   if ((!st->showmeter)&&(i)) 
				   {  
					   if(!(st->displayWnd=CreateWindow("Meter_Class", st->wndcaption, WS_CLIPSIBLINGS| WS_CHILD | WS_CAPTION | WS_THICKFRAME ,st->left, st->top, st->right-st->left, st->bottom-st->top, ghWndMain, NULL, hInst, NULL)))
							report_error("can't create Meter Window");
					   else { st->last_value=0; ShowWindow( st->displayWnd, TRUE ); UpdateWindow( st->displayWnd ); }
				   }
				   st->showmeter=i;
				}
				break;

			}
			return TRUE;
			
		case WM_HSCROLL:
		{
			int nNewPos; float x;

			nNewPos=get_scrollpos(wParam,lParam);

			if (lParam == (long) GetDlgItem(hDlg,IDC_AVGINTERVALBAR))  SetDlgItemInt(hDlg, IDC_AVGINTERVAL,nNewPos,0);
			if (lParam == (long) GetDlgItem(hDlg,IDC_ADAPTINTERVALBAR))  SetDlgItemInt(hDlg, IDC_ADAPTINTERVAL,nNewPos,0);
			if (lParam == (long) GetDlgItem(hDlg,IDC_AVGGAINBAR))  SetDlgItemInt(hDlg, IDC_AVGGAIN,nNewPos,TRUE);
			if (lParam == (long) GetDlgItem(hDlg,IDC_BARSIZEBAR))  SetDlgItemInt(hDlg, IDC_BARSIZE,nNewPos,TRUE);
			if (lParam == (long) GetDlgItem(hDlg,IDC_FONTSIZEBAR))  SetDlgItemInt(hDlg, IDC_FONTSIZE,nNewPos,TRUE);
			if (lParam == (long) GetDlgItem(hDlg,IDC_AVGFROMBAR))
			{  
				  x=size_value(0.0f,1000.0f,(float)nNewPos,st->in_ports[0].in_min,st->in_ports[0].in_max,0);
				  sprintf(temp,"%.2f",x);
				  SetDlgItemText(hDlg, IDC_AVGFROM, temp);

			}
			if (lParam == (long) GetDlgItem(hDlg,IDC_AVGTOBAR))  
			{  
				  x=size_value(0.0f,1000.0f,(float)nNewPos,st->in_ports[0].in_min,st->in_ports[0].in_max,0);
			   	  sprintf(temp,"%.2f",x);
				  SetDlgItemText(hDlg, IDC_AVGTO, temp);
			}
			apply_threshold(hDlg,st);
			if (st->displayWnd) {st->last_value=INVALID_VALUE; st->redraw=1; InvalidateRect(st->displayWnd,NULL,TRUE);}
		
		}	break;
		case WM_SIZE:
		case WM_MOVE:  update_toolbox_position(hDlg);
		case WM_PAINT:
			color_button(GetDlgItem(hDlg,IDC_SELECTCOLOR),st->color);
			color_button(GetDlgItem(hDlg,IDC_BKCOLOR),st->bkcolor);
			color_button(GetDlgItem(hDlg,IDC_FONTCOL),st->fontcolor);
			color_button(GetDlgItem(hDlg,IDC_FONTBKCOL),st->fontbkcolor);
		break;
	}
    return FALSE;
}
コード例 #5
0
ファイル: moravec_done.c プロジェクト: district10/homework
/* ============================================================
 * = Main
 * ============================================================*/
int main(int argc, char **argv)
{
  puts(">>>>>>>>>>>>>> Moravec Point Feature Detector");

  // Define Kernel Size and Moravec Threshold
  int moravec_kernel_size;
  int moravec_threshold;

  // Define raw-image holder 
  img_t raw_src;
 
  /* ------------------------------------------------------------
   * Load Image and Init Kernel Size and Threshold
   * ------------------------------------------------------------*/

  char *path = "data/u0367panLeft.raw";
  int row = 887;
  int col = 805;
  int ker_size = 3;
  int thresh = 30;

  // Not work now...
/* parse_params(argc,
	       argv,
	       &path,
	       &row,
	       &col,
	       &ker_size,
	       &thresh);*/
  
  // So we do it explicitely
  if (argc == 1) {
    puts(">> Use Built-in Params.");
  } else if (argc == 6) {
    puts(">> Load Params from Console. Single Thresh");
    path = argv[1];
    row = atoi(argv[2]);
    col = atoi(argv[3]);
    ker_size = atoi(argv[4]);
    thresh = atoi(argv[5]);
  } else if (argc > 7) {
    puts(">> Load Params from Console. Multi Thresh");
    path = argv[1];
    row = atoi(argv[2]);
    col = atoi(argv[3]);
    ker_size = atoi(argv[4]);
    if (atoi(argv[5]) != 0) { // argv[5] is treated as a flag
      puts("Multi Thresh Usage.");
      printf(">>  %s <raw_img_path> <row> <col> <kernel_size> 0 <threshold1> <threshold2> ...\n", argv[0]);
      exit (-1);
    }
    thresh = atoi(argv[6]); // this case, argv[6] as the threshold
  } else { // Else? Else Print out Usage and then exit!
    help(argc, argv);
    exit (-1);
  }

  printout_params(argv[0], path, row, col, ker_size, thresh);


  puts(">>>>>>>>>>>>>> Load Image & Set Kernel Size, Threshold");
  load_img(&raw_src, path, row, col);
  set_moravec_kernel_size(&moravec_kernel_size, ker_size);
  set_moravec_threshold(&moravec_threshold, thresh);

  // check 
  puts(">>>>>>>>>>>>>> Check Params");
  printf("## Check:\n##>> r:%d, c:%d; k: %d, t: %d\n", row, col, moravec_kernel_size, moravec_threshold); 

  /* ------------------------------------------------------------
   *  Define Variables and then Processing
   * ------------------------------------------------------------*/
  // Differences
  img_t raw_diff_l_r, raw_diff_t_b, raw_diff_tl_br, raw_diff_tr_bl;
  // Square Sums of Differences
  img_t raw_sqsum_l_r, raw_sqsum_t_b, raw_sqsum_tl_br, raw_sqsum_tr_bl; 
  // Min of Squares
  img_t output_sqsum_min; 
  // output: as a mask
  img_t output_01_mask; 

  puts(">>>>>>>>>>>>>> Differences");
  // DIFF 
  diff_left_right(raw_src,
		  &raw_diff_l_r);
  diff_top_bottom(raw_src,
		  &raw_diff_t_b);
  diff_topleft_bottomright(raw_src,
			   &raw_diff_tl_br);
  diff_topright_bottomleft(raw_src,
			   &raw_diff_tr_bl);
  
  puts(">>>>>>>>>>>>>> SqSum"); 
  // SQSUM
  sqsum_left_right(raw_diff_l_r,
		   &raw_sqsum_l_r,
		   moravec_kernel_size);
  sqsum_top_bottom(raw_diff_t_b,
		   &raw_sqsum_t_b,
		   moravec_kernel_size);
  sqsum_topleft_bottomright(raw_diff_tl_br,
			    &raw_sqsum_tl_br,
			    moravec_kernel_size);
  sqsum_topright_bottomleft(raw_diff_tr_bl,
			    &raw_sqsum_tr_bl,
			    moravec_kernel_size);

  puts(">>>>>>>>>>>>>> Min of Four"); 
  // MIN
  four2one(&output_sqsum_min, 
	   raw_sqsum_l_r,
	   raw_sqsum_t_b,
	   raw_sqsum_tl_br,
	   raw_sqsum_tr_bl);
 
  puts(">>>>>>>>>>>>>> Apply Threshold"); 
  apply_threshold(output_sqsum_min,
		  &output_01_mask,
		  moravec_threshold);

  char outpath[60];
  sprintf(outpath, "thrld_%d.%s", moravec_threshold, "raw");
  printf(">> Save to file: %s", outpath);
  save_img(&output_01_mask, outpath);

  // if there are other thresholds
  if (atoi(argv[5]) == 0) {
    for (int t = 7; t < argc; ++t) {
      set_moravec_threshold(&moravec_threshold, atoi(argv[t]));
      apply_threshold(output_sqsum_min,
		      &output_01_mask,
		      moravec_threshold);
      sprintf(outpath, "thrld_%d.%s", moravec_threshold, "raw");
      printf(">> Save to file: %s", outpath);
      save_img(&output_01_mask, outpath);
    }
  }

  return 0;
}