㈠ 使用OpenCV獲取攝像頭圖像,編碼壓縮並發送的問題
opencv用CvVideoWriter 來寫視頻文件,先用 cvCreateVideoWriter創建CvVideoWriter對象的,第二個參數寫「-1」,就可以選擇壓縮編碼方式
㈡ 請教怎麼用opencv將一張模糊的圖片變清晰
用opencv只能改善圖片清晰度,但是不能將將一張模糊的圖片變清晰的!因為圖像清晰度是有拍攝相機像素高低決定的!
㈢ opencv如何將連續圖像壓縮成視頻
這是我之前寫的一段代碼
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
/*******************************************************
圖片轉換為視頻
*******************************************************/
//void ImagetoVideo()
main()
{
int i = 0;
//初始化視頻編寫器,參數根據實際視頻文件修改
CvVideoWriter* writer = 0;
int isColor = 1;
//int fps = 25; // or 30
double fps = 6;
int frameW = 1920;
int frameH = 1080;
writer = cvCreateVideoWriter("decoderout.avi",CV_FOURCC('X','V','I','D'),fps, cvSize(frameW, frameH), isColor);
printf("\tvideo height:%d\n\tvidoe width:%d\n\t\fps:%d\n",frameH, frameW, fps);
int startframe = 1; //圖片開始幀號
int endframe = 58;
char cur_fn[255];
char* prefix = "F:\\視頻增強\\視頻解碼\\videoDecoder5-7-常式-先得到每一個nal\\img\\";//圖片序列的路徑
char* ext = ".bmp"; //序列圖片的後綴名
//存儲視頻文件
IplImage* img = 0;
// int nFrames = 50;
// for (i = 0; i < nFrames; i++)
// {
// cvWriteFrame(writer,img); //寫入一幀到一個視頻文件中 cvGrabFrame(capture);
// }
while (startframe <= endframe)
{
strcpy(cur_fn,"");
sprintf(cur_fn,"%s%d%s",prefix,startframe,ext);
img = cvLoadImage(cur_fn,isColor);
if (!img)
{
printf("can not open file\n");
return ;
}
cvWriteFrame(writer,img);
cvWaitKey(20);
startframe++;
cvReleaseImage(&img);
}
//創建窗口
// cvNamedWindow("mainWin",CV_WINDOW_AUTOSIZE);
// cvShowImage("mainWin",img);
// cvWaitKey(20);
//釋放視頻存儲器
cvReleaseVideoWriter(&writer);
}