Skip to content

Instantly share code, notes, and snippets.

View SubhiH's full-sized avatar

Soubhi Hadri SubhiH

View GitHub Profile
@SubhiH
SubhiH / OpencvWrapper.h
Created March 4, 2018 15:43
Face detection
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface OpencvWrapper : NSObject
+ (UIImage *)detect:(UIImage *)source;
@end
@SubhiH
SubhiH / OpencvWrapper.mm
Created March 4, 2018 15:45
Face detection
#import "OpencvWrapper.h"
#import <opencv2/opencv.hpp>
#import <opencv2/objdetect/objdetect.hpp>
#import <opencv2/objdetect.hpp>
@implementation OpencvWrapper
cv::CascadeClassifier face_cascade;
cv::CascadeClassifier eyes_cascade;
bool cascade_loaded = false;
@SubhiH
SubhiH / PrefixHeader.pch
Created March 4, 2018 15:51
Face detection
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
#ifdef __cplusplus
#include <opencv2/opencv.hpp>
#endif
#endif /* PrefixHeader_pch */
#import "OpencvWrapper.h"
@SubhiH
SubhiH / ViewController.swift
Created March 4, 2018 15:54
Face detection
import UIKit
class ViewController: UIViewController, FrameExtractorDelegate {
@IBOutlet var imageview: UIImageView!
var frameExtractor: FrameExtractor!
func captured(image: UIImage) {
imageview.image = OpencvWrapper.detect(image);
}
@SubhiH
SubhiH / main.cpp
Created December 20, 2018 21:49
Read streaming from camera and show RGB and Gray images
#include <iostream>
#include "opencv2/opencv.hpp"
int main() {
cv::VideoCapture cam(0);
if (!cam.isOpened()) {
throw std::runtime_error("Error");
}
cv::namedWindow("Window");
@SubhiH
SubhiH / main.cpp
Created December 21, 2018 00:28
ImageOperator class
class ImageOperator{
public:
ImageOperator() = default;
~ImageOperator() = default;
static void to_gray_m1(const cv::Mat& input, cv::Mat& output);
static void to_gray_m2(const cv::Mat& input, cv::Mat& output);
static void to_gray_m3(const cv::Mat& input, cv::Mat& output);
static void to_gray(const unsigned char* input,
const int width,
@SubhiH
SubhiH / ImageOperator.cpp
Created December 21, 2018 04:48
Convert RGB image to gray scale using iterator in OpenCV C++
void ImageOperator::to_gray_m1(const cv::Mat &input, cv::Mat &output) {
unsigned char *data_out = (unsigned char*)(output.data);
int ind = 0;
auto end = input.end<cv::Vec3b>();
cv::MatConstIterator_<cv::Vec3b> it = input.begin<cv::Vec3b>();
for (; it != end; ++it) {
const unsigned char &r = (*it)[2];
const unsigned char &g = (*it)[1];
const unsigned char &b = (*it)[0];
@SubhiH
SubhiH / ImageOperator.cpp
Created December 21, 2018 15:29
Convert RGB image to gray scale by looping through pixels using OpenCV
void ImageOperator::to_gray_m2(const cv::Mat &input, cv::Mat &output) {
unsigned char *data_in = (unsigned char*)(input.data);
unsigned char *data_out = (unsigned char*)(output.data);
int index = 0;
int byte_size = input.channels()*input.rows*input.cols;
while(index!=byte_size){
data_out[index/input.channels()] = unsigned(0.11*data_in[index]+0.59*data_in[index+1]+0.3*data_in[index+2]);
index+=3;
@SubhiH
SubhiH / ImageOperator.cpp
Created December 21, 2018 16:08
Convert RGB image to gray scale by looping through pixels (two for loops) using OpenCV
void ImageOperator::to_gray_m3(const cv::Mat &input, cv::Mat &output) {
unsigned char *data_in = (unsigned char*)(input.data);
unsigned char *data_out = (unsigned char*)(output.data);
int index = 0;
for (int row = 0; row < input.rows; ++row) {
for (int col = 0; col < input.cols*input.channels(); col+=input.channels()) {
data_out[index]= 0.11*data_in[row*input.step+col]+
0.59*data_in[row*input.step+col+1]+