简体   繁体   English

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

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

I already have my codes for body detection and it works fine. 我已经有了用于身体检测的代码,并且可以正常工作。 I want to finish it with a transparent image (a shirt for example) overlays on a real-time opencv camera when a body is detected. 我想在检测到人体时在实时opencv摄像机上覆盖透明图像(例如衬衫)来完成它。 I used haar cascade classifier for detection, by the way. 顺便说一下,我使用了haar级联分类器进行检测。

Here are my c++ codes for the human body detection: 这是我的用于人体检测的c ++代码:

nerds_thesis_clartips_OpencvClass.cpp 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));

   }

And here are my codes in my h file: 这是我的h文件中的代码:

nerds_thesis_clartips_OpencvClass.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

I'm still noob in this field and this will serves as my final output in college. 我在这个领域仍然是菜鸟,这将是我在大学的最终成果。

You have to use alpha bending for this purpose. 为此,必须使用alpha弯曲。 In order to construct a transparent overlay, you need two images: 为了构造透明的叠加层,您需要两个图像:

  • Your original image. 您的原始图片。
  • An image containing what you want to “overlay” on top of the first using some level of alpha transparency. 图像,其中包含您要使用某种级别的Alpha透明度“叠加”在第一个图像上的图像。

Here is an example for transparent overlay image but it is in python 这是透明覆盖图像的示例,但它在python中
https://www.pyimagesearch.com/2016/03/07/transparent-overlays-with-opencv/ https://www.pyimagesearch.com/2016/03/07/transparent-overlays-with-opencv/

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

Below is a implementation for aplha bending in c++ but to make the overlay image transparent you have to see the logic in first link above. 以下是在c ++中进行aplha弯曲的实现,但是要使覆盖图像透明,您必须在上面的第一个链接中查看逻辑。 https://www.learnopencv.com/alpha-blending-using-opencv-cpp-python/ https://www.learnopencv.com/alpha-blending-using-opencv-cpp-python/

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

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