Skip to content

Instantly share code, notes, and snippets.

View ochilab's full-sized avatar

おちラボ ochilab

View GitHub Profile
@ochilab
ochilab / ProgressBaronStatus.cs
Created June 24, 2013 11:31
ステータスバーにプログレスバーを表示する(C#)
ToolStripProgressBar ProgressBar = new ToolStripProgressBar();
ProgressBar.Minimum = 0; //下限値
ProgressBar.Maximum = 100; //上限値
ProgressBar.Value = 0; //現在値
ProgressBar.Style = ProgressBarStyle.Blocks;
statusStrip1.Items.Add(ProgressBar);
@ochilab
ochilab / CaptureUSBCamByOpenCV.cpp
Created June 26, 2013 06:34
OpenCVにてUSBカメラの映像を表示(C++/CLI)
IplImage* img_frame;
CvCapture* capture;
array<int,2>^data;
Bitmap^ bmp;
//カメラの接続確認
if(capture==NULL){
if((capture=cvCreateCameraCapture(-1))==NULL){
MessageBox::Show("カメラが見つかりません");
return;
@ochilab
ochilab / MonochromeCV.cpp
Created June 26, 2013 06:38
OpenCVでモノクロ処理
for (y = 0; y < img_frame->height; y++) {
for (x = 0; x < img_frame->width; x++) {
p[0] = img_frame->imageData[img_frame->widthStep * y + x * 3]; // B
p[1] = img_frame->imageData[img_frame->widthStep * y + x * 3 + 1]; // G
p[2] = img_frame->imageData[img_frame->widthStep * y + x * 3 + 2]; // R
img_frame->imageData[img_frame->widthStep * y + x * 3] = cvRound((p[0] + p[1] + p[2]) / 3);
img_frame->imageData[img_frame->widthStep * y + x * 3 + 1] = cvRound((p[0] + p[1] + p[2]) / 3);
img_frame->imageData[img_frame->widthStep * y + x * 3 + 2] = cvRound((p[0] + p[1] + p[2]) / 3);
}
@ochilab
ochilab / MosaicCV.cpp
Created June 26, 2013 06:44
モザイク処理(C++/CLI)。モザイクサイズについてはちょっと修正の必要あり。
int blue, green , red;
int tmp1, tmp2;
int x, y;
int size = 10;//モザイクサイズ
for(int y=0;y<img_frame->height;y+=size){
for(int x=0;x<img_frame->width;x+=size){
blue = 0;
green = 0;
red = 0;
@ochilab
ochilab / SocketServer.cpp
Created June 26, 2013 06:54
ソケットでサーバプログラム(CPP/CLI)
Socket ^myListenSocket;
Socket ^mySessionSocket;
NetworkStream ^myStream;
StreamReader ^myReader;
BinaryReader ^myBReader;
IPAddress ^myAddress;
int myPort;
EndPoint ^myEndPoint;
myListenSocket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp);
IplImage2Array(IplImage* image){
CvScalar color;
unsigned char r;
unsigned char g;
unsigned char b;
int rgb;
for(int y=0; y<image->height; y++){
for(int x=0; x<image->width; x++){
Array2Bitmap(Bitmap^ bmp){
Imaging::BitmapData^ bmpData;
unsigned char* pBmpSrc;
int wStep;
unsigned char r;
unsigned char g;
unsigned char b;
int rgb;
bmpData=bmp->LockBits(
@ochilab
ochilab / CameraCaptureOpenCV.cs
Last active February 25, 2016 05:19
OpenCVにてUSBカメラの映像を表示する(OpenCVSharp利用)
Cv.NamedWindow("sample", WindowMode.AutoSize);
CvCapture videoCapture = Cv.CreateCameraCapture(0); //ここはUSBカメラのID
//サイズを320,240にしておかないとエラーになる感じ
double w = 320, h = 240;
Cv.SetCaptureProperty(videoCapture, CaptureProperty.FrameWidth, w);
Cv.SetCaptureProperty(videoCapture, CaptureProperty.FrameHeight, h);
if (videoCapture == null){
//ここでカメラがない場合のエラー処理
}
@ochilab
ochilab / KinectStream_InteractionFrameReady.cs
Created June 26, 2013 09:24
Kinect のInteractionFrameを扱うサンプル。ここでは、手のグリップ情報を取り出しています。
void stream_InteractionFrameReady(object sender, InteractionFrameReadyEventArgs e){
using (var interactionFrame = e.OpenInteractionFrame()){
if (interactionFrame != null){
var userInfos = new UserInfo[InteractionFrame.UserInfoArrayLength];
interactionFrame.CopyInteractionDataTo(userInfos);
List<InteractionHandPointer> hands = new List<InteractionHandPointer>();
foreach (var user in userInfos){
if (user.SkeletonTrackingId != 0){
foreach (var hand in user.HandPointers){
@ochilab
ochilab / _SampleQuickSort.c
Created June 26, 2013 10:50
クイックソートのサンプルプログラム(C)
#include <stdio.h>
#define swap(type, x, y) do { type t = x; x = y; y = t; } while (0)
/*--- クイックソート ---*/
void quick(int a[], int left, int right){
int pl = left; /* 左カーソル */
int pr = right; /* 右カーソル */
int x = a[(pl+pr)/2]; /* 枢軸は中央の要素 */
int i;