Kaynağa Gözat

use ffmpeg scale 8*8

DevYK 3 yıl önce
ebeveyn
işleme
0a7230bd79
2 değiştirilmiş dosya ile 11 ekleme ve 9 silme
  1. 2 2
      src/ffmpeg/av_decode.cpp
  2. 9 7
      src/opencv/image_fingerprint.cpp

+ 2 - 2
src/ffmpeg/av_decode.cpp

@@ -106,10 +106,10 @@ static int av_decode(struct DecoderContext *pContext, AVPacket *pPacket, enum AV
             return 0;
         }
 
-        LOGE("decode is video=%d pts=%lld \n",pPacket->stream_index == pContext->st_index[AVMEDIA_TYPE_VIDEO],pts);
+//        LOGE("decode is video=%d pts=%lld \n",pPacket->stream_index == pContext->st_index[AVMEDIA_TYPE_VIDEO],pts);
         if (pts>=14000)
         {
-            LOGE("decode is video=%d pts=%lld \n",pPacket->stream_index == pContext->st_index[AVMEDIA_TYPE_VIDEO],pts);
+//            LOGE("decode is video=%d pts=%lld \n",pPacket->stream_index == pContext->st_index[AVMEDIA_TYPE_VIDEO],pts);
 
         }
         if (pts < pContext->start_time && pContext->start_time >= 0 && pContext->force_Iframe != 1) {

+ 9 - 7
src/opencv/image_fingerprint.cpp

@@ -11,8 +11,9 @@ int avframeToCvmat(cv::Mat &image, const AVFrame *frame) {
     int height = frame->height;
     int cvLinesizes[1];
     cvLinesizes[0] = image.step1();
+    int scale_width =8,scale_height = 8;
     printf("cvmatToAvframe width=%d height=%d linesize[0]=%d  linesize[1]=%d  linesize[2]=%d \n",width,height,frame->linesize[0],frame->linesize[1],frame->linesize[2]);
-    SwsContext *conversion = sws_getContext(width, height, (AVPixelFormat) frame->format, width, height,
+    SwsContext *conversion = sws_getContext(width, height, (AVPixelFormat) frame->format, scale_width, scale_height,
                                             AVPixelFormat::AV_PIX_FMT_BGR24, SWS_FAST_BILINEAR, NULL, NULL, NULL);
     if (conversion) {
         sws_scale(conversion, frame->data, frame->linesize, 0, height, &image.data, cvLinesizes);
@@ -77,8 +78,9 @@ int fingerprintFromFFAVFrame(FILE *file, AVFrame *frame, char buf[64]) {
 
     int width = frame->width;
     int height = frame->height;
+    int scale_width = 8, scale_height = 8;
     printf("fingerprintFromFFAVFrame -1\n");
-    cv::Mat img(height, width, CV_8UC3);
+    cv::Mat img(scale_height, scale_width, CV_8UC3);
     printf("fingerprintFromFFAVFrame -2\n");
     int ret = avframeToCvmat(img, frame);
     if (ret < 0) {
@@ -94,17 +96,17 @@ int fingerprintFromFFAVFrame(FILE *file, AVFrame *frame, char buf[64]) {
     printf("fingerprintFromFFAVFrame 2\n");
 //    std::string str = frame->pts + "";
 //    imshow(str, img);
-    int scale_width = 8, scale_height = 8;
+
     cv::Mat gray, res;
     if (file) fprintf(file, "fingerprintFromFFAVFrame 3\n");
     printf("fingerprintFromFFAVFrame 3\n");
     //缩放成8x8大小灰度图
-    resize(img, res, Size(scale_width, scale_height));
-    img.release();
+//    resize(img, res, Size(scale_width, scale_height));
+//    img.release();
     if (file) fprintf(file, "fingerprintFromFFAVFrame 4\n");
     printf("fingerprintFromFFAVFrame 4\n");
-    cvtColor(res, gray, COLOR_BGR2GRAY);
-    res.release();
+    cvtColor(img, gray, COLOR_BGR2GRAY);
+    img.release();
     if (file) fprintf(file, "fingerprintFromFFAVFrame 5\n");
     printf("fingerprintFromFFAVFrame 5\n");
     //获取灰度平均值