1、庫(linux+qt):
libs+=/usr/local/lib/libopencv_highgui.so \
/usr/local/lib/libopencv_core.so \
/usr/local/lib/libopencv_imgproc.so \
/usr/local/lib/libopencv_imgcodecs.so
2、讀取:
cv::imread(std::string imgpath,cv::mat img)
3、顯示:
cv::imshow(std::string dialogname,cv::mat img)
4、等待:
cv::waitkey(int time)
5、儲存:
cv::imwrite(std::string filename,cv::mat img)
6、縮放:
cv::resize(cv::mat src, cv::mat dst, cv::size dsize, double fx=0, double fy=0, int interpolation=cv::inter_linear );
cv::mat src 原圖
cv::mat dst 縮放後的圖
cv::size dsize 為0,則按照dsize = size(round(fx*src.cols), round(fy*src.rows))(round函式double取整),不為0則按此尺寸
fx,fy 長寬縮放比
int interpolation 插值方式,預設cv::inter_linear
cv::videocapture cap(std::string videofile);
if (!cap.isopened())
cv::mat frame;
//獲取幀長
long frame_num=static_cast(cap.get(cv_cap_prop_frame_count));
double rate = cap.get(cv_cap_prop_fps);
int delay = 1000/rate;
while(true)
if (cap.isopened())
8、呼叫攝像頭
cv::videocapture cap;
cap.open(0);
if(!cap.isopened())
return;
cv::mat frame;
while(1)
if (cap.isopened())
cap.release();
9、擷取roi
//從src擷取roi到dst
cv::mat src(cv::rect roi).copyto(cv::mat dst);
10、畫矩形
cv::rectangle(cv::mat img, rect rec,cv::scalar(0, 0, 255), 2, 8, 0);
11、新增文字
cv::puttext( cv::mat img,std::string text, cv::point org,
int fontface, double fontscale, scalar color,
int thickness = 1, int linetype = line_8,
bool bottomleftorigin = false );
附所有的opencv庫(每台電腦可能不一樣的):
/usr/local/lib/libopencv_aruco.so \
/usr/local/lib/libopencv_aruco.so\
/usr/local/lib/libopencv_bgsegm.so\
/usr/local/lib/libopencv_bioinspired.so\
/usr/local/lib/libopencv_calib3d.so\
/usr/local/lib/libopencv_ccalib.so\
/usr/local/lib/libopencv_core.so\
/usr/local/lib/libopencv_cudaarithm.so\
/usr/local/lib/libopencv_cudabgsegm.so\
/usr/local/lib/libopencv_cudacodec.so\
/usr/local/lib/libopencv_cudafeatures2d.so\
/usr/local/lib/libopencv_cudafilters.so\
/usr/local/lib/libopencv_cudaimgproc.so\
/usr/local/lib/libopencv_cudalegacy.so\
/usr/local/lib/libopencv_cudaobjdetect.so\
/usr/local/lib/libopencv_cudaoptflow.so\
/usr/local/lib/libopencv_cudastereo.so\
/usr/local/lib/libopencv_cudawarping.so\
/usr/local/lib/libopencv_cudev.so\
/usr/local/lib/libopencv_datasets.so\
/usr/local/lib/libopencv_dnn.so\
/usr/local/lib/libopencv_dpm.so\
/usr/local/lib/libopencv_face.so\
/usr/local/lib/libopencv_face.so.3.1\
/usr/local/lib/libopencv_features2d.so\
/usr/local/lib/libopencv_flann.so\
/usr/local/lib/libopencv_fuzzy.so\
/usr/local/lib/libopencv_hdf.so\
/usr/local/lib/libopencv_highgui.so\
/usr/local/lib/libopencv_imgcodecs.so\
/usr/local/lib/libopencv_imgproc.so\
/usr/local/lib/libopencv_line_descriptor.so\
/usr/local/lib/libopencv_ml.so\
/usr/local/lib/libopencv_objdetect.so\
/usr/local/lib/libopencv_optflow.so\
/usr/local/lib/libopencv_photo.so\
/usr/local/lib/libopencv_plot.so\
/usr/local/lib/libopencv_reg.so\
/usr/local/lib/libopencv_rgbd.so\
/usr/local/lib/libopencv_saliency.so\
/usr/local/lib/libopencv_shape.so\
/usr/local/lib/libopencv_stereo.so\
/usr/local/lib/libopencv_stitching.so\
/usr/local/lib/libopencv_structured_light.so\
/usr/local/lib/libopencv_superres.so\
/usr/local/lib/libopencv_su***ce_matching.so\
/usr/local/lib/libopencv_text.so\
/usr/local/lib/libopencv_tracking.so\
/usr/local/lib/libopencv_videoio.so\
/usr/local/lib/libopencv_video.so\
/usr/local/lib/libopencv_videostab.so\
/usr/local/lib/libopencv_xfeatures2d.so\
/usr/local/lib/libopencv_ximgproc.so\
/usr/local/lib/libopencv_xobjdetect.so\
/usr/local/lib/libopencv_xphoto.so\
OpenCV 常用操作
影象的讀取 顯示 修改 儲存 影象的讀取函式 imread arg 1 arg 2 第乙個引數為所讀取影象的名字,型別為string 第二個引數為指明影象的格式。常用的格式有 imread unchanged 0 以單通道的形式讀取 imread grayscale 0 以強度圖 灰度圖 的形式讀取...
OpenCV中陣列 矩陣 的常用操作
本文 ggicci 的網易部落格 function 函式名 use 函式用處 add矩陣加法a b的更高階形式,支援mask scaleadd 矩陣加法,乙個帶有縮放因子dst i scale src1 i src2 i addweighted 矩陣加法,兩個帶有縮放因子dst i saturate...
opencv的矩陣操作
1 建立乙個大小為100 100的3通道2維矩陣,並將其所有資料置0,然後在上面畫乙個圓形並顯示這幅影象 include cv.h include cxcore.h include highgui.h include stdio.h int main return 0 執行結果如下圖 2 建立乙個擁...