Rather than Processing, it's no longer just java
After posting, I noticed that the contents of Mat will be negative, so I should have used an int array instead of a byte array ... Mat.get () is overloaded ...
import org.opencv.core.*;
import org.opencv.highgui.*;
VideoCapture capture;
void setup(){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
capture = new VideoCapture(0);
fullScreen();
}
void draw(){
background(0);
if (capture.isOpened()) {
Mat video = new Mat();
capture.read(video);
byte [] b;
b = new byte[(int)video.size().height * (int)video.size().width*3];
video.get(0,0,b);
PImage img = createImage((int)video.size().width,(int)video.size().height,ARGB);
for(int i=0;i<(int)video.size().width;i++){
for(int j=0;j<(int)video.size().height;j++){
int p = (i+j*(int)video.size().width)*3;
img.set(i,j,color(fix(b[p+2]),fix(b[p+1]),fix(b[p+0])));
}
}
image(img, 0, 0, (int)video.size().width, (int)video.size().height);
}
}
int fix(int val){
if(val>-1)return val;
else{
return 256+val;
}
}
reference -Basic processing of cv :: Mat ・ Using OpenCV with Qiita Processing (continued)
Recommended Posts