Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed yesterday.
Improve this question
I wanted to use a mask on the original image, but I somehow get this error code that I don't understand at all:
error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\core\src\arithm.cpp:230: error: (-215:Assertion failed) (mtype == CV_8U || mtype == CV_8S) && _mask.sameSize(*psrc1) in function 'cv::binary_op'
The code is the following:
mask = np.zeros(image[:,:,0].shape)
mask[np.where( ( image[:,:,2]<60/255 ) & ( image[:,:,0]>100/255 ) ) ] = 1
result = cv2.bitwise_and(image, image, mask=mask)
I couldn't find any answer anywhere.
The mask I want to use:
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 days ago.
Improve this question
Code:
import geopandas as gpd
import rasterio as rio
capital_cities = gpd.read_file(r'C:\Users\user\Desktop\SHP\Bangladesh_shapefile_Feature.shp')
capital_cities['Temp']=0
for index, row in capital_cities.iterrows() :
city= row['DISTNAME']
longitude=row['geometry'].x
latitude=row['geometry'].y
temp_raster = rio.open(r'C:\Users\user\Desktop\Output raster\c2019GDP_Clip.tif')
temp_data = temp_raster.read(1)
rowIndex, colIndex = temp_raster.index(longitude, latitude)
print(city +':'+str(temp_data[rowIndex, colIndex]))
My primary objective is to export the data in the CSV file.
Your code is fine. It is working on my side...
I understand that what you re printing at the end is what you expect your csv to be (later, for now you re just output in console).
That error "IndexError: index 774 is out of bounds for axis 0 with size 724" make me think to a projection system issue !!
Do both vector and raster layer have projection system defined properly? Are they in same projection system (must be...)?
Even with points that are not within the extent of the raster, you should have retrieved a nodata value (eg: -3.402823e+38 ), not raising an exception...
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I tried to write some line of code for quick sort algorithm using numpy algorithm.
But It seems not working properly .
Can you help me solve it ?
import numpy as np
def quick_sort_np(narr):
"""A numpy version of quick sort algorithm"""
narr = np.array(narr)
if len(narr)<= 1 :
return narr
p = narr[-1] # I take the last item as pivot by convension
print (f"at this level the pivot is {p}")
lnarr = narr[narr<p]
print (f"----------------------> left arr is {lnarr}")
rnarr = narr[narr>p]
print (f"----------------------> right arr is {rnarr}")
return quick_sort_np(lnarr) + p + quick_sort_np(rnarr)
in case of [1,2,6,5,4,8,7,99,33] as input my code returns nothing and that's the question.
+ acting on np.arrays is element wise addition, not concatenation.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
def hourglassSum():
for i in range(0,6):
arr1=map(int,input().split())
arr=list(arr1)
sum=[]
for i in range(len(arr)-2):
for j in range(len(arr)-2):
sum.append(arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2])
maxi=max(sum)
print(maxi)
hourglassSum()
This code shows the following error:
TypeError: 'int' object is not subscriptable
How to fix it?
I suspect that's what you're looking for:
def hourglassSum():
arr = []
for i in range(0,6):
arr1=map(int,input().split())
arr.append(list(arr1))
sum=[]
for i in range(len(arr)-2):
for j in range(min(len(arr[i]), len(arr[i+1]), len(arr[i+2]))-2):
sum.append(arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2])
maxi=max(sum)
print(maxi)
Two notes:
(1) you want to persist each iteration of the first loop, what you were doing was just overwriting your variable with each iteration
(2) while iterating across different elements of elements of your base list - always make sure you won't run into index out of bounds exception - I presume your approach was to put in 6x6 elements - so it's just to mitigate eventual discrepancies
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
So I'm using opencv, numpy, and python for a computer vision project. I'm going off of this tutorial: http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html
and have followed it exactly (minus a few minor changes which are apparent in the code). I'm not sure why I'm getting this error (below) and would really appreciate some insight on this. Thanks!
Code:
def applyHarrisCornerDetection():
image1 = cv2.imread('pictures/board1.png')
image2 = cv2.imread('pictures/board2.png')
gray1 = cv2.cvtColor(image1,cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(image2,cv2.COLOR_BGR2GRAY)
gray1 = np.float32(gray1)
gray2 = np.float32(gray2)
dst1 = cv2.cornerHarris(gray1,2,3,0.04)
dst2 = cv2.cornerHarris(gray2,2,3,0.04)
dst1 = cv2.dilate(dst1,None)
dst2 = cv2.dilate(dst2,None)
img1[dst1>0.01*dst1.max()]=[0,0,255]
img2[dst2>0.01*dst2.max()]=[0,0,255]
cv2.imshow('dst1',img1)
cv2.imshow('dst2',img2)
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()
Error:
It's because of these two lines:
img1[dst1>0.01*dst1.max()]=[0,0,255]
img2[dst2>0.01*dst2.max()]=[0,0,255]
You are assigning elements to some position in a list, but that list hasn't been initialized.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
It's seems that resizing to smaller sizes (thumbnails) works fine. However, resizing to bigger sizes does not work. Do you know why? What would you suggest as an alternative?
.resize() accepts tuple, be it a request to down-scale or to up-scale
works both directions
>>> from PIL import Image # .INIT
>>> im = Image.open( "ColorLookUpTABLE___TEST_CHART.png" ) # .GET 258,200 [px]
>>> imB = im.resize( ( 516, 400 ) ) # .SET 516,400 [px] a double
>>> imB # .CHK instance
<PIL.Image.Image image mode=P size=516x400 at 0x19D9968>
>>> imB.show() # .GUI shown