Skip to content

Instantly share code, notes, and snippets.

View AllanChen's full-sized avatar

AllanChan AllanChen

View GitHub Profile
//OpenCV Convert YUV buffer to rgb mat
Mat y(actual_size, CV_8UC1);
Mat u(half_size, CV_8UC1);
Mat v(half_size, CV_8UC1);
//
memcpy(y.data, frame_buffer->DataY(), actual_size.width * actual_size.height);
memcpy(u.data, frame_buffer->DataU(), half_size.width * half_size.height);
memcpy(v.data, frame_buffer->DataV(), half_size.width * half_size.height);
//
@AllanChen
AllanChen / WMFVideoReadWrite.cpp
Created February 19, 2022 07:48 — forked from m1keall1son/WMFVideoReadWrite.cpp
C++ Program to read a video file and re-encode it to H.264 / AAC using Windows Media Foundation
//USAGE $ program.exe path\\to\\video-in.mp4 path\\to\\video-out.mp4
#include <iostream>
#include <string>
#include <mfidl.h> // Media Foundation interfaces
#include <mfapi.h> // Media Foundation platform APIs
#include <mferror.h> // Media Foundation error codes
#include <mfreadwrite.h>
#include <wmcontainer.h> // ASF-specific components
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="xxxx@gmail.com"
CORRECT_NAME="www"
CORRECT_EMAIL="www@gmail.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
//int ArmSkySegPreprocessor::resize_cpp(const VN_Image *__input, const VN_Image *__out) {
// const uint8_t *src = (uint8_t *) __input->data;
// uint8_t *dst = (uint8_t *) __out->data;
// uint64_t src_h = (uint64_t) __input->height;
// uint64_t src_w = (uint64_t) __input->width;
// uint64_t dst_h = (uint64_t) __out->height;
// uint64_t dst_w = (uint64_t) __out->width;
//
// float scale_y = static_cast<float>(src_h) / static_cast<float>(dst_h);
// float scale_x = static_cast<float>(src_w) / static_cast<float>(dst_w);
//
// ViewCtrl_CPUEasyImageProcessing.m
// demo_ios
//
// Created by yyuser on 2018/10/19.
//
#import "ViewCtrl_CPUEasyImageProcessing.h"
#import "vn_core.h"
#import "vn_yuvconverter.h"
@AllanChen
AllanChen / gist:a21844a517aaf1fcc23f8fd229568a8a
Created March 13, 2020 11:33
bilinear c4, c3 also c1,c2 done
void resize_bilinear_c4(uint8_t *dst, const uint8_t *src,
uint64_t dst_h, uint64_t dst_w, uint64_t src_h,
uint64_t src_w) {
float scale_y = static_cast<float>(src_h) / static_cast<float>(dst_h);
float scale_x = static_cast<float>(src_w) / static_cast<float>(dst_w);
for (int h = 0; h < dst_h; h++) {
const int y = (int)MIN(static_cast<uint64_t>(h * scale_y), src_h - 1);
for (int w = 0; w < dst_w; w++) {
const int x = (int)MIN(static_cast<uint64_t>(w * scale_x), src_w - 1);
@AllanChen
AllanChen / yuv_nv12_to_rgb24
Last active April 19, 2021 06:02
The function is the algorithm by yuv nv12 to rgb.
/*
* How to use this funtion
*/
- (void)videoCaptureCallback:(CVPixelBufferRef)pixelBuffer{
// [self test_yuv_to_rgb:pixelBuffer];
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
int width = (int)CVPixelBufferGetWidth(pixelBuffer);
int height = (int)CVPixelBufferGetHeight(pixelBuffer);
unsigned char *yBuffer = (unsigned char*)CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0); //ybuffer
@AllanChen
AllanChen / cpp mat multiply
Last active October 17, 2019 03:02
cpp mat multiply
#include<iostream>
using namespace std;
void create_mat(int height, int width, float *outMat){
for (int h=0; h<height; h++){
for (int w=0; w<width; w++){
float value = h * width + (w+1);
int int_value = (int) value -1;
outMat[int_value] = value;
@AllanChen
AllanChen / swift open camera and call delegate
Created September 10, 2019 06:45
swift open camera and call delegate
import UIKit
import AVFoundation
import Accelerate
var customPreviewLayer: AVCaptureVideoPreviewLayer?
class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate {
var captureSession: AVCaptureSession?
var dataOutput: AVCaptureVideoDataOutput?
@AllanChen
AllanChen / gist:ea2123c59f11871e76efa2d3d48dcea2
Created August 29, 2019 09:07
NEON INT 16 command test
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self neonCommandTest];