日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > pytorch >内容正文

pytorch

完整opencv(emgucv)人脸、检测、采集、识别、匹配、对比

發(fā)布時間:2023/12/18 pytorch 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 完整opencv(emgucv)人脸、检测、采集、识别、匹配、对比 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

//成對幾何直方圖匹配????????
????? public static string MatchHist()?????????
????? {
????????? string haarXmlPath = @"haarcascade_frontalface_alt_tree.xml";
????????? HaarCascade haar = new HaarCascade(haarXmlPath);
????????? int[] hist_size = new int[1] { 256 };//建一個數(shù)組來存放直方圖數(shù)據(jù)
????????? //IntPtr img1 = CvInvoke.cvLoadImage("", Emgu.CV.CvEnum.LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_ANYCOLOR); //根據(jù)路徑導(dǎo)入圖像
???????????????
????????? //準備輪廓?
????????? Image<Bgr, Byte> image1 = new Image<Bgr, byte>("D:\\code\\picture\\frunck.jpg");
????????? Image<Bgr, Byte> image2 = new Image<Bgr, byte>("D:\\code\\picture\\lena.jpg");
????????? MCvAvgComp[] faces = haar.Detect(image1.Convert<Gray, byte>(), 1.4, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20), Size.Empty);
????????? MCvAvgComp[] faces2 = haar.Detect(image2.Convert<Gray, byte>(), 1.4, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20), Size.Empty);

????????? int l1 = faces.Length;
????????? int l2 = faces2.Length;
????????? image1 = image1.Copy(faces[0].rect);
????????? image2 = image2.Copy(faces2[0].rect);
????????? Image<Gray, Byte> imageGray1 = image1.Convert<Gray, Byte>();
????????? Image<Gray, Byte> imageGray2 = image2.Convert<Gray, Byte>();
????????? Image<Gray, Byte> imageThreshold1 = imageGray1.ThresholdBinaryInv(new Gray(128d), new Gray(255d));
????????? Image<Gray, Byte> imageThreshold2 = imageGray2.ThresholdBinaryInv(new Gray(128d), new Gray(255d));
????????? //Contour<Point> contour1 = imageThreshold1.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL);
????????? Contour<Point> contour1 = imageThreshold1.FindContours();
????????? Contour<Point> contour2 = imageThreshold2.FindContours();
????????? IntPtr HistImg1 = CvInvoke.cvCreateHist(1, hist_size, Emgu.CV.CvEnum.HIST_TYPE.CV_HIST_ARRAY, null, 1); //創(chuàng)建一個空的直方圖
????????? IntPtr HistImg2 = CvInvoke.cvCreateHist(1, hist_size, Emgu.CV.CvEnum.HIST_TYPE.CV_HIST_ARRAY, null, 1);

    //CvInvoke.cvHaarDetectObjects();

????????? IntPtr[] inPtr1 = new IntPtr[1] { imageThreshold1 };
????????? IntPtr[] inPtr2 = new IntPtr[1] { imageThreshold2 };
????????? CvInvoke.cvCalcHist(inPtr1, HistImg1, false, IntPtr.Zero); //計算inPtr1指向圖像的數(shù)據(jù),并傳入HistImg1中
????????? CvInvoke.cvCalcHist(inPtr2, HistImg2, false, IntPtr.Zero);
????????? Stopwatch sw = new Stopwatch();?
????????? sw.Start();?
????????? double compareResult;
????????? Emgu.CV.CvEnum.HISTOGRAM_COMP_METHOD compareMethod =? Emgu.CV.CvEnum.HISTOGRAM_COMP_METHOD.CV_COMP_BHATTACHARYYA;
????????? CvInvoke.cvNormalizeHist(HistImg1, 1d); //直方圖對比方式
????????? CvInvoke.cvNormalizeHist(HistImg2, 1d);
????????? compareResult = CvInvoke.cvCompareHist(HistImg1, HistImg2, compareMethod);
????????? //compareResult = CvInvoke.cvMatchShapes(HistImg1, HistImg2, Emgu.CV.CvEnum.CONTOURS_MATCH_TYPE.CV_CONTOURS_MATCH_I3, 1d);
????????? sw.Stop();
????????? double time = sw.Elapsed.TotalMilliseconds;
????????? return string.Format("成對幾何直方圖匹配(匹配方式:{0}),結(jié)果:{1:F05},用時:{2:F05}毫秒\r\n", compareMethod.ToString("G"), compareResult, time);
?????????
????? }?

總結(jié)

以上是生活随笔為你收集整理的完整opencv(emgucv)人脸、检测、采集、识别、匹配、对比的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。