-1

I'm trying to find the 10 max values of the .csv file that Harris algorithm gives as output. May you help me? I find a way to find the max value but not 10 first.

import cv2
import numpy as np
from numpy import genfromtxt

filename = 'boy.jpg'

img = cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

gray = np.float32(gray)
dst = cv2.cornerHarris(gray, 2, 3, 0.04)

# result is dilated for making the corners, not important
dst = cv2.dilate(dst, None)

# Threshold for an optional value, it may vary depending on the image.
img[dst > 0.01 * dst.max()] = [0, 0, 255]

cv2.imshow('dst', img)

np.savetxt("data2.csv", dst, delimiter=",")

if cv2.waitKey(0) & 0xff == 27:
    cv2.destroyAllWindows()

import numpy
data1 = numpy.genfromtxt("data2.csv",dtype='float',delimiter =',', skip_header=0, skip_footer=0,usecols=11,usemask=True)
#print data1
print(data1.min())
print(data1.max())
martineau
  • 119,623
  • 25
  • 170
  • 301
ChrisK25
  • 23
  • 5
  • 1
    There are quite a few solutions on this site for finding the `N` largest values in a data set. Generally, you sort and then take the top values from there. I'm confused by your posting, as most of your code seems to have nothing to do with handling values from a CSV file. – Prune Jan 15 '19 at 17:31

1 Answers1

1

Sort the dataframe by a column, then print out the first 10.

df.sort_values('some_column', ascending=False)[:10]
atlas
  • 410
  • 4
  • 14
  • it cant be sorted by a column, cause if u open the specific file in excel, except it is huge, it doesn't show the right values. the right values are only shown if u open the .csv file in pycharm. – ChrisK25 Jan 15 '19 at 17:37
  • `df.columns` will yield the column names of your dataframe. I'm assuming the value of the Harris algorithm is the column you want sorted. Use this column name to sort the values: `df.sort_values('Harris_alg', ascending=False)[:10]` – atlas Jan 15 '19 at 17:50