Fast way of copying byte array in C/C++ (With measurements)

UPD 2017: these are early experimnts on c++ compiler optimizations. I don’t think it is useful any more. I have the following code for copying several buffers from one object to another: 1 2 3 4 5 6 7 8 9 // Copy several buffers (images) for( int i = 0; i < MIN( conf_.size(), src.conf_.size() ); ++ i ) { // Copy pixels for( int j = 0; j < MIN( sizeOfBuffer_, src....

October 15, 2013 · SergeM

Using h264/multiview codec from Intel Media SDK

I needed to launch multiview compression using codec from Intel MVC. Approximately a half a year ago I launched it normally. Yesterday it tried and I got such an error: $ ./sample_encode.exe h264 -i input.yuv -o output.h264 -w 1920 -h 1080 Return on error: error code -3, .\src\pipeline_encode.cpp 865 Return on error: error code 1, .\src\sample_encode.cpp 343 Frame number: 0 I started debug and found out the error appears in...

October 11, 2013 · SergeM

Некоторые заметки о приведении типов в СиПлюсПлюс

АлёнаC++: http://alenacpp.blogspot.ru/2005/08/c.html static_cast между указателями корректно, только если один из указателей - это указатель на void или если это приведение между объектами классов, где один класс является наследником другого. То есть для приведения к какому-либо типу от void*, который возвращает malloc, следует использовать static_cast. int * p = static_cast<int*>(malloc(100)); Если приведение не удалось, возникнет ошибка на этапе компиляции. Однако, если это приведение между указателями на объекты классов вниз по иерархии и оно не удалось, результат операции undefined....

October 4, 2013 · SergeM

OpenCV. Copy image from unsigned char buffer, resize and save to file

How to copy image from unsigned char buffer, resize and save to file. If you use single-channel image. #include <opencv/cv.h> #include <opencv/highgui.h> int coeff = 4; cv::Mat src( height, width, CV_8UC1, (void *) source_byte_beffer ) ); cv::Mat small(height/ coeff, width/ coeff, CV_8UC1 ); cv::Size s_half(width/ coeff, height/ coeff); cv::resize( src, small, s_half, 1, 1, cv::INTER_LINEAR ); // resize from src to small IplImage* writeImage; writeImage=cvCloneImage(&(IplImage)src); cvSaveImage("src1.bmp", writeImage); cvReleaseImage( &writeImage ); writeImage=cvCloneImage(&(IplImage)small); cvSaveImage("little....

July 9, 2013 · SergeM

Error spawning cmd.exe

I got error message Error spawning cmd.exeduring compiling of Blender sources. The cause was in system PATH environment variable. Some buggy software I had installed and uninstalled before erased all contents of PATH. So I found out that Visual Studio 2008 has missing paths to %SystemRoot%\system32; %SystemRoot%; %SystemRoot%\System32\Wbem;A added it and the problem gone. 

May 12, 2013 · SergeM

Blinking multiple LEDs with Arduino (ATMega328p) and PCA9685

Arduino (ATMega328p) boards can be used to control multiple LEDs. To simplify the management of the pulse width modulation and use only a couple of arduino's pins for many LEDs I used PCA9685 controller. PCA9685 is connected to Arduino using I2C interface that requires only two data pins. Arduino connects to PCA9685 using Adafruit_PWMServoDriver library: #include <Adafruit_PWMServoDriver.h> Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); Initialization in setup(): pwm.begin(); pwm.setPWMFreq(1600); // This is the maximum PWM frequency Then for each loop we will blink with 2 LEDs....

SergeM

Capture PWM signal using Arduino

Parsing PWM signals For my robocar project I needed to understand the mechanism of pulse width modulation of the remote control. My intention was to use Arduino as a proxy between RC-receiver and servos/ESC to be able to record the used input for imitation learning. Human driver (me) sends steering commands via the remote control (transmitter). RC receiver converts radio signal into PWM signal. Arduino captures and maybe filters the signal, saves it somehow and sends it to the servos/ESC....

SergeM