Python kullanarak openCV 3.0'da LineIterator kullanmak istiyorum, hala python için oluşturulmuş openCV 3.0 ile kullanılabilir mi? İnternet üzerindeki cevapların hepsi, cv modülünün bir parçası olan cv.InitLineIterator'a işaret ediyor gibi görünüyor. Bu modülü içe aktarmayı denedim ancak mevcut yapıya dahil edilmemiş gibi görünüyor. Yeniden adlandırıldı mı veya tamamen kaldırıldı mı?openCV 3.0 python LineIterator
9
A
cevap
20
Kendi sorunumu çözdüm. Line yineleyici, cv2 kitaplığında kullanılamaz gibi görünüyor. Bu yüzden kendi satır yineleyicimi yaptım. Döngü kullanılmaz, bu yüzden oldukça hızlı olmalıdır. Herhangi bir kullanıcının buna ihtiyacı varsa kodu:
def createLineIterator(P1, P2, img):
"""
Produces and array that consists of the coordinates and intensities of each pixel in a line between two points
Parameters:
-P1: a numpy array that consists of the coordinate of the first point (x,y)
-P2: a numpy array that consists of the coordinate of the second point (x,y)
-img: the image being processed
Returns:
-it: a numpy array that consists of the coordinates and intensities of each pixel in the radii (shape: [numPixels, 3], row = [x,y,intensity])
"""
#define local variables for readability
imageH = img.shape[0]
imageW = img.shape[1]
P1X = P1[0]
P1Y = P1[1]
P2X = P2[0]
P2Y = P2[1]
#difference and absolute difference between points
#used to calculate slope and relative location between points
dX = P2X - P1X
dY = P2Y - P1Y
dXa = np.abs(dX)
dYa = np.abs(dY)
#predefine numpy array for output based on distance between points
itbuffer = np.empty(shape=(np.maximum(dYa,dXa),3),dtype=np.float32)
itbuffer.fill(np.nan)
#Obtain coordinates along the line using a form of Bresenham's algorithm
negY = P1Y > P2Y
negX = P1X > P2X
if P1X == P2X: #vertical line segment
itbuffer[:,0] = P1X
if negY:
itbuffer[:,1] = np.arange(P1Y - 1,P1Y - dYa - 1,-1)
else:
itbuffer[:,1] = np.arange(P1Y+1,P1Y+dYa+1)
elif P1Y == P2Y: #horizontal line segment
itbuffer[:,1] = P1Y
if negX:
itbuffer[:,0] = np.arange(P1X-1,P1X-dXa-1,-1)
else:
itbuffer[:,0] = np.arange(P1X+1,P1X+dXa+1)
else: #diagonal line segment
steepSlope = dYa > dXa
if steepSlope:
slope = dX.astype(np.float32)/dY.astype(np.float32)
if negY:
itbuffer[:,1] = np.arange(P1Y-1,P1Y-dYa-1,-1)
else:
itbuffer[:,1] = np.arange(P1Y+1,P1Y+dYa+1)
itbuffer[:,0] = (slope*(itbuffer[:,1]-P1Y)).astype(np.int) + P1X
else:
slope = dY.astype(np.float32)/dX.astype(np.float32)
if negX:
itbuffer[:,0] = np.arange(P1X-1,P1X-dXa-1,-1)
else:
itbuffer[:,0] = np.arange(P1X+1,P1X+dXa+1)
itbuffer[:,1] = (slope*(itbuffer[:,0]-P1X)).astype(np.int) + P1Y
#Remove points outside of image
colX = itbuffer[:,0]
colY = itbuffer[:,1]
itbuffer = itbuffer[(colX >= 0) & (colY >=0) & (colX<imageW) & (colY<imageH)]
#Get intensities from img ndarray
itbuffer[:,2] = img[itbuffer[:,1].astype(np.uint),itbuffer[:,0].astype(np.uint)]
return itbuffer
İlgili konular
- 1. OpenCV 3.0'ı python
- 2. SimpleBlobDetector python için opencv 3.0 içinde bulunamadı
- 3. OpenCV 3.0 findContours çöküyor
- 4. cv :: Mat.refcount OpenCV 2.4.9 OpenCV 3.0
- 5. KNN train(), cv2 ile birlikte opencv 3.0
- 6. OpenCV Python
- 7. Harici modül OpenCV 3.0'da eksik
- 8. Opencv Python raw image
- 9. OpenCV PCA Compute Python
- 10. Python, OpenCV: opencv_traincascade
- 11. Python OpenCV bağlantılarında copyA eşittir?
- 12. Python OpenCV Contour ağaç hiyerarşisi
- 13. python - OpenCV mat :: convertTo python'da
- 14. Python openCV: kmeans örneği çalışmıyor
- 15. Python ve gpu OpenCV fonksiyonları
- 16. opencv
- 17. OpenCv 3.0.0
- 18. HSV2BGR dönüşümü Python OpenCV betiğinde başarısız oluyor
- 19. OpenCV Python: Draw minAreaRect (RotatedRect uygulanmadı)
- 20. Yüzleri bulanıklaştırmak için opencv (python) nasıl kullanılır?
- 21. Sudo olmadan python OpenCV programlarını nasıl yürütürüm?
- 22. python OpenCV mp4 videoları için kodek nedir?
- 23. OpenCV Python Araç Numarası Plaka Algılama
- 24. Python & OpenCV kullanarak kırmızı renk bulma
- 25. OpenCV Python ile 2 boyutlu görüntüde derinlik hatası Python
- 26. Opencv
- 27. OpenCV
- 28. OpenCV
- 29. OpenCV
- 30. OpenCV
İnanılmaz! işimi çok daha kolay bir hale getirdin –
Yanlış oylama yanlışlıkla oldu, cevabı değiştirmedikçe geri alamıyorum. Afedersiniz! :/ – eudoxos
@mohikhsan paylaşım için teşekkürler. Sadece satırın 'cv2.drawLine() 'ile verilen satırdan biraz farklı olduğunu belirtmek istedim: satırınız ilk noktayı' P1 'içermiyor,' cv2.drawLine()' buna dahil. – krookedking