Re: [問題] OpenCV 做透視轉換

看板C_and_CPP作者 (假斯汀)時間15年前 (2009/06/14 19:27), 編輯推噓3(3011)
留言14則, 3人參與, 最新討論串2/2 (看更多)
void fun3()// 透視轉換 { //透視變換 IplImage* Img_old; IplImage* Img_new; Img_old = cvLoadImage("lena.bmp",1); //載入圖像 int fix = 50; int w = Img_old->width + fix; int h = Img_old->height + fix; CvPoint2D32f src_point[4]; CvPoint2D32f dst_point[4]; //設定源觀察面,即指定四邊形的四個頂點 src_point[0].x=100; src_point[0].y=340; src_point[1].x=420; src_point[1].y=340; src_point[2].x=100; src_point[2].y=100; src_point[3].x=420; src_point[3].y=100; //設定目標觀察面,即指定四邊形的四個頂點 dst_point[0].x=-fix; dst_point[0].y=h; dst_point[1].x=w; dst_point[1].y=h; dst_point[2].x=-fix; dst_point[2].y=-fix; dst_point[3].x=w; dst_point[3].y=-fix; float newm[9]; CvMat newM = cvMat( 3, 3, CV_32F, newm ); //獲得透視轉換矩陣 cvWarpPerspectiveQMatrix(src_point,dst_point,&newM); //透視轉換 cvWarpPerspective(Img_old,Img_new,&newM,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0) ); cvNamedWindow("image",1); //創建窗口 cvShowImage("image",Img_new); //顯示圖像 cvWaitKey();//等待按鍵 cvDestroyWindow("OpenCV win");//銷毀窗口 cvReleaseImage(&Img_new);//釋放圖像 return; } 跑出來是沒有error,卻多了一堆warning warning C4244: '=' : conversion from 'int' to 'float', possible loss of data warning C4700: uninitialized local variable 'Img_new' used 基本上是這兩種錯誤 有人可以幫指點一下嗎? 感謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.62.36.60

06/14 19:35, , 1F
CvPoint2D32f 是float型別 Img_new你沒用到
06/14 19:35, 1F

06/14 19:57, , 2F
那要把x、y重新宣告嗎?Img_new是我要輸出的圖
06/14 19:57, 2F

06/14 19:59, , 3F
那應該要怎麼寫才好呢?謝謝回答
06/14 19:59, 3F

06/14 20:08, , 4F
Img_new 宣告成指標型態, 要再 cvCreateImage
06/14 20:08, 4F

06/14 20:09, , 5F
CvPoint2D32f src_point,dst_point
06/14 20:09, 5F

06/14 20:10, , 6F
要改成 src_point[0].x=100.f 否則會出現 warning
06/14 20:10, 6F

06/14 20:10, , 7F
不過這個沒差
06/14 20:10, 7F

06/14 21:30, , 8F
wa大,我宣告改成指標後就OK了,但cvCreateImage部份還
06/14 21:30, 8F

06/14 21:31, , 9F
是有點問題耶似乎格式不太對
06/14 21:31, 9F
Img_new = cvCreateImage( cvSize(320,240), Img_old->depth, Img_old->nChannels); ※ 編輯: SiriusJinn 來自: 140.120.90.174 (06/14 21:33)

06/14 21:38, , 10F
建議用cvGetSize(Img_old) 取代 cvSize()如果size有相關的話
06/14 21:38, 10F

06/14 21:41, , 11F
我修改成功了,可以正確顯圖了,只是不太像透視轉換= =
06/14 21:41, 11F

06/14 21:43, , 12F
圖都跑到左上角去了
06/14 21:43, 12F

06/14 22:25, , 13F
出現0xC000001D錯誤怎麼辦?
06/14 22:25, 13F

06/14 23:40, , 14F
圖跑到左上角,dst_point的座標調整一下
06/14 23:40, 14F
文章代碼(AID): #1ADDwd8Q (C_and_CPP)
文章代碼(AID): #1ADDwd8Q (C_and_CPP)