opencv實現分水嶺演算法

2021-09-10 17:18:53 字數 2659 閱讀 1705

//  分水嶺演算法原理

//  iplimage* marker_mask = 0;iplimage* markers = 0;//iplimage* img0 = 0, *img = 0, *img_gray = 0, *wshed = 0;iplimage  *img_gray = 0, *wshed = 0;cvpoint prev_pt = ;void

on_mouse

( int event, int x, int y, int flags, void* param )

}void ccvmfcview::onwatershed()//分水嶺   break;  }  if( c == 'r' )    if( c == 'w' || c == '\r' )      color_tab = cvcreatemat( 1, comp_count, cv_8uc3 );    for( i = 0; i < comp_count; i++ )            // paint the watershed image

for( i = 0; i < markers->height; i++ )      }    }    cvaddweighted( wshed, 0.5, img_gray, 0.5, 0, wshed );  //  影象合成

//    cvshowimage( "watershed transform", wshed );    cvreleasememstorage( &storage );    cvreleasemat( &color_tab );   }   else    cvcopy(wshed,workimg);   cvflip(workimg);   cclientdc dc

(this)

;   stretchdibits(dc.m_hdc,         //  重新整理主視窗

0,0,workimg->width,workimg->height,    0,0,workimg->width,workimg->height,    workimg->imagedata,m_lpbmi,dib_rgb_colors,srccopy);   flag=1;  } } cvdestroywindow( "image" ); cvreleaseimage(&img0); cvreleaseimage(&img); cvreleaseimage(&img_gray); cvreleaseimage(&marker_mask); cvreleaseimage(&markers); cvflip(wshed); m_dibflag=imagereplace(wshed,&workimg); invalidate();}

再分享一下我老師大神的人工智慧教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智慧的隊伍中來!

//  分水嶺演算法原理

//  iplimage* marker_mask = 0;iplimage* markers = 0;//iplimage* img0 = 0, *img = 0, *img_gray = 0, *wshed = 0;iplimage  *img_gray = 0, *wshed = 0;cvpoint prev_pt = ;void

on_mouse

( int event, int x, int y, int flags, void* param )

}void ccvmfcview::onwatershed()//分水嶺   break;  }  if( c == 'r' )    if( c == 'w' || c == '\r' )      color_tab = cvcreatemat( 1, comp_count, cv_8uc3 );    for( i = 0; i < comp_count; i++ )            // paint the watershed image

for( i = 0; i < markers->height; i++ )      }    }    cvaddweighted( wshed, 0.5, img_gray, 0.5, 0, wshed );  //  影象合成

//    cvshowimage( "watershed transform", wshed );    cvreleasememstorage( &storage );    cvreleasemat( &color_tab );   }   else    cvcopy(wshed,workimg);   cvflip(workimg);   cclientdc dc

(this)

;   stretchdibits(dc.m_hdc,         //  重新整理主視窗

0,0,workimg->width,workimg->height,    0,0,workimg->width,workimg->height,    workimg->imagedata,m_lpbmi,dib_rgb_colors,srccopy);   flag=1;  } } cvdestroywindow( "image" ); cvreleaseimage(&img0); cvreleaseimage(&img); cvreleaseimage(&img_gray); cvreleaseimage(&marker_mask); cvreleaseimage(&markers); cvflip(wshed); m_dibflag=imagereplace(wshed,&workimg); invalidate();}

opencv 分水嶺演算法

分水嶺演算法是一種簡單的影象分割演算法,具體是人為規定兩點 以兩點為例 然後把這兩點看做低谷,向裡面注水,不停地蔓延,直到兩點形成的湖交界。opencv自帶了這個程式。摘抄如下,其中我做了一些修改。本程式的目的是測試分水嶺演算法 include include include include usi...

OpenCV的分水嶺演算法

本文使用python實現 import cv2 as cv import numpy as np def watershed demo src print src.shape blurred cv.pyrmeanshiftfiltering src,10,100 去雜訊 gray cv.cvtcol...

OpenCV之分水嶺演算法

在許多實際的應用中,我們需要分割影象,但是無法從背景影象中獲得有用資訊。但是分水嶺演算法在這方面往往非常有效,它可以將影象中的邊緣轉化為 山脈 將均勻區域轉化為 山谷 這樣有助於分割目標。分水嶺演算法是一種記憶拓撲理論的數學形態學的分割方法,其基本思想是把影象看作測地學上的拓撲地貌,影象中每點畫素的...