Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中实现OpenCV TPS ShapeTransformer时出现的问题_Python_Opencv_Image Processing - Fatal编程技术网

在Python中实现OpenCV TPS ShapeTransformer时出现的问题

在Python中实现OpenCV TPS ShapeTransformer时出现的问题,python,opencv,image-processing,Python,Opencv,Image Processing,我正在尝试使用Python在OpenCV中使用ThinPlateSplineShapeTransformer实现图像扭曲。我使用的是OpenCV论坛()中发布的C++示例,但是由于OpenCV Python API的不同,我遇到了各种各样的问题。 正如在链接的示例中一样,我使用的是单个图像,我将在其上定义少量的源点和相应的目标点。最终结果应该是图像的扭曲副本。目前的守则如下: tps=cv2.createThinPlateSplineShapeTransformer() sourceshape

我正在尝试使用Python在OpenCV中使用ThinPlateSplineShapeTransformer实现图像扭曲。我使用的是OpenCV论坛()中发布的C++示例,但是由于OpenCV Python API的不同,我遇到了各种各样的问题。 正如在链接的示例中一样,我使用的是单个图像,我将在其上定义少量的源点和相应的目标点。最终结果应该是图像的扭曲副本。目前的守则如下:

tps=cv2.createThinPlateSplineShapeTransformer()

sourceshape= np.array([[200,10],[400,10]],np.int32)
targetshape= np.array([[250,10],[450,30]],np.int32)

matches=list()
matches.append(cv2.DMatch(1,1,0))
matches.append(cv2.DMatch(2,2,0))

tps.estimateTransformation(sourceshape,targetshape,matches)
但是我在estimateTransformation方法中得到了一个错误:

cv2.error: D:\Build\OpenCV\opencv-3.1.0\modules\shape\src\tps_trans.cpp:193: error: (-215) 
(pts1.channels()==2) && (pts1.cols>0) && (pts2.channels()==2) && (pts2.cols>0) in function cv::ThinPlateSplineShapeTransformerImpl::estimateTransformation 
我可以理解,我传递给estimateTransformation的数据结构中存在错误,我猜这与通道有关,因为行和列似乎是正确的,但我不知道如何满足断言(pts1.channels()==2)因为参数是我正在创建的点数组,而不是从图像加载生成的数组


如果您能为使用Python进行图像转换提供TPS实现方面的指导,或者为解决这个问题提供帮助,我将不胜感激。我已经尝试为PythPultHaPulExchange类找到Python文档,但是事实证明这是不可能的——我所发现的只是C++文档,我唯一需要做的就是帮助()函数的结果-如果我丢失了明显的

< P>,我也有同样的问题。简单的重塑解决了这个问题。虽然很晚了,但有人可能会觉得它很有用。以下是重塑
sourceshape
targetshape
的行:

sourceshape=sourceshape.reshape(1,-1,2)
targetshape=targetshape.reshape(1,-1,2)

你能检查一下匹配点的数量吗。在您的代码中,只有两个匹配点,很难进行插值。可能你最多可以增加四个匹配点,比这更有效

sourceshape= np.array([[200,10],[400,10]],np.int32)//increase more point here
targetshape= np.array([[250,10],[450,30]],np.int32)//increase more point here

matches=list()
matches.append(cv2.DMatch(1,1,0))
matches.append(cv2.DMatch(2,2,0))
//add more matches here.

任何人有人吗?你找到解决办法了吗。请分享。我得到了以下错误:
OpenCV错误:在CV::gemmImpl文件C:\projects\OpenCV python\OpenCV\modules\core\src\matmul.cpp,第1190行,断言失败(type==CV\u 64FC2),我不太了解这个错误,但我认为是类型错误。尝试将其转换为np.int32。或其他格式。