Skip to content

Instantly share code, notes, and snippets.

View SubhiH's full-sized avatar

Soubhi Hadri SubhiH

View GitHub Profile
from typing import Optional, Dict, Any
import hashlib
import json
import os
import logging
from datetime import datetime, timedelta, timezone
from google.adk.plugins.base_plugin import BasePlugin
from google.adk.agents.callback_context import CallbackContext
from google.adk.models.llm_request import LlmRequest
from google.adk.models.llm_response import LlmResponse
@SubhiH
SubhiH / ImageOperator.cpp
Last active July 13, 2023 05:18
Flip image horizontally and vertically
void ImageOperator::flip_h(const unsigned char* input,
const int width,
const int height,
const int channel,
unsigned char*& output){
for (int row = 0; row < height; ++row) {
for (int col = 0; col < width * channel; col += 1) {
output[row*width+col]=input[(height-row)*width+col];
@SubhiH
SubhiH / ImageOperator.cpp
Created December 26, 2018 23:21
Rotate an image
void ImageOperator::rotate(const unsigned char* input,
const int width,
const int height,
const int channel,
unsigned char*& output){
unsigned char* tmp = new unsigned char[width*height*channel];
int step = channel*width;
for (int row = 0; row < height; ++row) {
for (int col = 0; col < width*channel; col+=channel) {
@SubhiH
SubhiH / ImageOperator.cpp
Created December 26, 2018 23:04
Rotate gray scale image
void ImageOperator::rotate(const unsigned char* input,
const int width,
const int height,
const int channel,
unsigned char*& output){
unsigned char* tmp = new unsigned char[width*height*channel];
for (int row = 0; row < height; ++row) {
for (int col = 0; col < width; col+=1) {
tmp[col*width+width-1-row] = input[row*width+col];
int main() {
cv::VideoCapture cam(0);
if (!cam.isOpened()) {
throw std::runtime_error("Error");
}
cv::namedWindow("Window");
while(true){
void ImageOperator::rotate(const unsigned char* input,
const int width,
const int height,
const int channel,
unsigned char* output){
for (int row = 0; row < height; ++row) {
for (int col = 0; col < width; col+=1) {
output[col*width+width-1-row] = input[row*width+col];
}
@SubhiH
SubhiH / main.cpp
Last active December 22, 2018 18:28
Convert RGB image to gray scale test CPP C++
#include <iostream>
#include "opencv2/opencv.hpp"
int main() {
cv::VideoCapture cam(0);
if (!cam.isOpened()) {
throw std::runtime_error("Error");
}
@SubhiH
SubhiH / ImageOperator.cpp
Created December 21, 2018 16:37
Convert RGB image to gray scale by looping through pixels using char raw pointers C++
void ImageOperator::to_gray(const unsigned char* bgr_input,
const int width,
const int height,
const int channel,
unsigned char* gray_output){
int index = 0;
int step = channel*width;
for (int row = 0; row < height; ++row) {
for (int col = 0; col < width*channel; col+=channel) {
gray_output[index] = 0.11*bgr_input[row*step+col]+
@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]+
@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;