imwrite()를 사용하여 이미지 (예 : "face.jpg")를 디스크에 쓸 수 있습니다. 그런 다음 fstream을 사용하여이 jpg를 배열로 읽습니다.이 배열은 내가 원하는 것입니다.Opencv Mat에서 이미지 스트림을 빠르게 얻는 방법?
하지만 어떻게 빨리 할 수 있습니까? memmory에서 디스크가 아닙니다. Mat.data의 이미지 데이터 길이가 Mat.cols * Mat.rows.i라고 생각했습니다. 맞지 않거나 올바르지 않습니다. 그래서 fstream을 디스크에 쓴 다음 이미지 뷰어로 열었습니다. 틀린 것이 틀림 없다.
Mat frame;
VideoCapture cap(0);
if (!cap.isOpened())
{
return -1;
}
cap.set(CV_CAP_PROP_FRAME_WIDTH, 160);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 120);
cap >> frame;
if(frame.empty()){
return -2;
}
//I just want the pointer and length of image information,the following is just for testing
//whether that the same as I thought,if it's right ,frame.data and len is what I want,but it not work.
FILE *fp = fopen("face.jpg", "wb");
if (NULL==fp)
{
return -1;
}
int len = frame.cols*frame.rows; //or 3*frame.cols*frame.rows
fwrite(frame.data, len, sizeof(char), fp);
fclose(fp);
namedWindow("face", 1);
imshow("face", frame);
waitKey(1000);
나는 OpenCV의 새로운 해요, 난 그냥 도움을 이미지 data.thanks를 얻을 싶어!
당신이 원하는 수 있음'imencode()'http://docs.opencv.org/3.0-beta/modules/imgcodecs/doc/reading_and_writing_images.html#imencode – ZdaR
정확히 달성하려고하는거야? 이미지에서 다른 구조로 원시 바이트를 복사 하시겠습니까? – slawekwin
frame.cols * frame.rows는 이미지가 연속적인 경우에만 true입니다. 너비가 477이 아니라 16의 배수가 아니라면 각 행 끝에 패딩이 추가 될 수 있습니다. 16 또는 32이지만 패딩에 2의 제곱을 사용했는지 기억하지 못합니다. – saurabheights