opencv imwrite保存图像不成功的问题
问题描述:
1.用c++写了一个动态库,功能是:在图片上画直线;coding:
int __stdcall img_line(char* sImagePath, char* rImagePath, int startx, int starty, int endx, int endy, int thickness, int bgr_fst, int bgr_sec, int bgr_thr) {
Mat imgs = imread(sImagePath);
Point start = Point(startx, starty);
Point end = Point(endx, endy);
if(!imgs.empty()){
try{
line(imgs, start, end, Scalar(bgr_fst, bgr_sec, bgr_thr), thickness);
//imshow("处理后图片", imgs);
imwrite(rImagePath, imgs);
}catch (runtime_error& ex) {
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
return 1;
}
}
// 等待操作,关闭显示
waitKey(0);
return 0;
}
2.vb.net 调用这个函数:
Private Declare Function img_line Lib "VbCallOpenCv.dll" (ByVal sImagePath As String, ByVal startx As Long, ByVal starty As Long, ByVal endx As Long, ByVal endy As Long, ByVal thickness As Integer, ByVal bgr_fst As Long, ByVal bgr_sec As Long, ByVal bgr_thr As Long) As Long
Private Sub Drawline_Click(sender As Object, e As EventArgs) Handles drawline.Click
Dim images As String = pic_ath.Text ‘图片加载路径
Dim startx As Long = X_start.Text ’画线开始坐标x
Dim starty As Long = Y_start.Text ’画线开始坐标y
Dim endx As Long = X_end.Text ’画线终点坐标x
Dim endy As Long = Y_end.Text ’画线终点坐标y
Dim thickness As Long = 2 '线形
Dim bgr_fst As Long = tdf.Text '颜色B通道
Dim bgr_sec As Long = tds.Text '颜色G通道
Dim bgr_thr As Long = tdt.Text '颜色R通道
img_line(images, startx, starty, endx, endy, thickness, bgr_fst, bgr_sec, bgr_thr)
PicLine.Image = Image.FromFile(images)
End Sub
3.当第一次执行画线时可以保存成功!点击按钮画第二根直线时imshow()可以显示图片,但是imwrite()并没有执行,图像没有保存,这是什么原因?用c++测试调用img_line()没有问题。
请大侠们指点,是哪出的问题