繁体   English   中英

实时OpenCV摄像机上的透明图像叠加

[英]Transparent Image Overlay over Real-time OpenCV Camera

我已经有了用于身体检测的代码,并且可以正常工作。 我想在检测到人体时在实时opencv摄像机上覆盖透明图像(例如衬衫)来完成它。 顺便说一下,我使用了haar级联分类器进行检测。

这是我的用于人体检测的c ++代码:

nerds_thesis_clartips_OpencvClass.cpp

#include "nerds_thesis_clartips_OpencvClass.h"

JNIEXPORT void JNICALL Java_nerds_thesis_clartips_OpencvClass_humanDetection
  (JNIEnv *, jclass, jlong addrRgba){
    Mat& frame = *(Mat*)addrRgba;

    detectHuman(frame);
    }

  void detectHuman(Mat& frame){
    String human_cascade_name = "/storage/emulated/0/data/haarcascade_upperbody.xml";
    CascadeClassifier human_cascade;

    if(!human_cascade.load( human_cascade_name ) ) { printf("--(!)Error loading\n"); return; };

    std::vector<Rect> humans;
    Mat frame_gray;

    cvtColor( frame, frame_gray, CV_BGR2GRAY );
    equalizeHist( frame_gray, frame_gray);

    //-- Detect Human
    human_cascade.detectMultiScale( frame_gray, humans, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

    for (int i=0; i<humans.size(); i++)
        rectangle(frame, Point(humans[i].x, humans[i].y), Point(humans[i].x+humans[i].width, humans[i].y+humans[i].height), Scalar(0,255,0));

   }

这是我的h文件中的代码:

nerds_thesis_clartips_OpencvClass.h

#include <jni.h>
#include <opencv2/opencv.hpp>
/* Header for class nerds_thesis_clartips_OpencvClass */

using namespace cv;

#ifndef _Included_nerds_thesis_clartips_OpencvClass
#define _Included_nerds_thesis_clartips_OpencvClass
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     nerds_thesis_clartips_OpencvClass
 * Method:    humanDetection
 * Signature: (J)V
 */

 void detectHuman(Mat& frame);

JNIEXPORT void JNICALL Java_nerds_thesis_clartips_OpencvClass_humanDetection
  (JNIEnv *, jclass, jlong);

#ifdef __cplusplus
}
#endif
#endif

我在这个领域仍然是菜鸟,这将是我在大学的最终成果。

为此,必须使用alpha弯曲。 为了构造透明的叠加层,您需要两个图像:

  • 您的原始图片。
  • 图像,其中包含您要使用某种级别的Alpha透明度“叠加”在第一个图像上的图像。

这是透明覆盖图像的示例,但它在python中
https://www.pyimagesearch.com/2016/03/07/transparent-overlays-with-opencv/

https://pytech-solution.blogspot.in/2017/07/alphablending.html

以下是在c ++中进行aplha弯曲的实现,但是要使覆盖图像透明,您必须在上面的第一个链接中查看逻辑。 https://www.learnopencv.com/alpha-blending-using-opencv-cpp-python/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM