1

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. I used haar cascade classifier for detection, by the way.

Here are my c++ codes for the human body detection:

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:

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.

Abegail
  • 71
  • 10

1 Answers1

0

You have to use alpha bending for this purpose. 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.

Here is an example for transparent overlay image but it is in python
https://www.pyimagesearch.com/2016/03/07/transparent-overlays-with-opencv/

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. https://www.learnopencv.com/alpha-blending-using-opencv-cpp-python/

krishank Tripathi
  • 616
  • 1
  • 7
  • 23
  • The thing is, it's not an image overlays an image. I want to put a transparent overlay on a real-time opencv cam, augmented reality-like. – Abegail Feb 17 '18 at 13:08
  • Can you still help me about this? I badly need it :( – Abegail Feb 18 '18 at 16:44
  • well i don't have done that deep work on this field but here a link that you might find use full https://stackoverflow.com/questions/14540210/opencv-python-draw-image-over-a-webcam-stream – krishank Tripathi Feb 19 '18 at 04:50
  • for augmented reality see this https://bitesofcode.wordpress.com/2017/09/12/augmented-reality-with-python-and-opencv-part-1/ – krishank Tripathi Feb 19 '18 at 05:02