我正在研究Rubik的侧扫描仪以确定立方体的状态。我对计算机视觉非常陌生并且使用它,所以它一直是一个挑战。到目前为止,我所做的是我使用视频捕获,并在某些帧捕获该帧并将其保存以进行图像处理。这是它的样子。 获取图像中像素的HSV值OpenCV
拍摄照片时,立方体每次都处于相同的位置,所以我不必担心定位贴纸。 我遇到的麻烦是在每个方块中获取一小部分像素来确定其HSV。
我知道HSV的范围大致
Red = Hue(0...9) AND Hue(151..180)
Orange = Hue(10...15)
Yellow = Hue(16..45)
Green = Hue(46..100)
Blue = Hue(101..150)
White = Saturation(0..20) AND Value(230..255)
所以之后我已经拍摄的图像,然后我加载它,分裂图像的HSV值,但不知道如何让某些像素坐标的形象。我该怎么做?
BufferedImage getOneFrame() {
currFrame++;
//At the 90th frame I capture that frame and save that frame
if (currFrame == 120) {
cap.read(mat2Img.mat);
mat2Img.getImage(mat2Img.mat);
Imgcodecs.imwrite("firstImage.png", mat2Img.mat);
}
cap.read(mat2Img.mat);
return mat2Img.getImage(mat2Img.mat);
}
public void splitChannels() {
IplImage firstShot = cvLoadImage("firstImage.png");
//I split the channels so that I can determine the value of the pixel range
IplImage hsv = IplImage.create(firstShot.width(), firstShot.height(), firstShot.depth(), firstShot.nChannels());
IplImage hue = IplImage.create(firstShot.width(), firstShot.height(), firstShot.depth(), CV_8UC1);
IplImage sat = IplImage.create(firstShot.width(), firstShot.height(), firstShot.depth(), CV_8UC1);
IplImage val = IplImage.create(firstShot.width(), firstShot.height(), firstShot.depth(), CV_8UC1);
cvSplit(hsv, hue, sat, val, null);
//How do I get a small range of pixels of my images to determine get their HSV?
}
没有具体的原因,为什么我使用'IplImage'我以前使用过'Mat',但是我找不到加载'Mat'图像的方法。并分割该图像的颜色通道。进入单独的HSV频道。 – cuber
使用'imread'和'cvtColor'以及网上发现的众多例子。 :) 祝你好运! – Nejc
我必须使用'cvtColor'我已经有了我想要的格式的图像。 – cuber