Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create negative_py #35

Open
reza320 opened this issue Apr 7, 2017 · 9 comments
Open

create negative_py #35

reza320 opened this issue Apr 7, 2017 · 9 comments

Comments

@reza320
Copy link

reza320 commented Apr 7, 2017

Hi!
when I am trying to run create negative_py, I get the error:
read_img_name = data_base_dir + '/' + file_list[current_image].strip()
IndexError: list index out of range
can u help me with this please?
I have just created 340 scenery images in the directory
btw, I am not a pro. just a beginner
thanks a lot!

@anson0910
Copy link
Owner

Hi,
Sorry, the script is indeed kind of messy!
I think you can try modifying line 51 to exit(0) instead of break

@reza320
Copy link
Author

reza320 commented Apr 7, 2017 via email

@anson0910
Copy link
Owner

Try adding print(number_of_pictures) on next line of line 14,
what does it print?

@reza320
Copy link
Author

reza320 commented Apr 7, 2017 via email

@microhua
Copy link

microhua commented Mar 19, 2018

I have added some lines in the code, is it OK?

 for current_image in range((current_neg_dir - 1)*300, (current_neg_dir - 1)*300 + 300):    # take 300 images
        if current_image > (number_of_pictures - 1):
            break
        if current_image % 100 == 0:
            print "Processing image number " + str(current_image)
        read_img_name = data_base_dir + '/' + file_list[current_image].strip()
        img = cv2.imread(read_img_name)     # read image
        height, width, channels = img.shape

        crop_size = min(height, width) / 2  # start from half of shorter side

        while crop_size >= 12:
            for start_height in range(0, height, 100):
                if (start_height + crop_size) > height:
                    break
                for start_width in range(0, width, 100):
                    if (start_width + crop_size) > width:
                        break
                    cropped_img = img[start_height : start_height + int(crop_size), start_width : start_width + int(crop_size)]

@anson0910
Copy link
Owner

Yes, this should work!

@hqq1990
Copy link

hqq1990 commented Jun 10, 2018

Hello, i'm also a beginner.
When i tried to modify the codes as you discuss.
It still said:"IndexError: list index out of range".

2018-06-10 4 02 16

2018-06-10 4 05 17

plz help me, thank you.

@anson0910
Copy link
Owner

Hi Hong,

I think the problem is wrong indentation compared to the code microhua pasted.
The code with the line starting from read_img_name should be indented to the right.

for current_image in range((current_neg_dir - 1)*300, (current_neg_dir - 1)*300 + 300):    # take 300 images
        if current_image > (number_of_pictures - 1):
            break
        if current_image % 100 == 0:
            print "Processing image number " + str(current_image)
        read_img_name = data_base_dir + '/' + file_list[current_image].strip()
        img = cv2.imread(read_img_name)     # read image
        height, width, channels = img.shape

        crop_size = min(height, width) / 2  # start from half of shorter side

        while crop_size >= 12:
            for start_height in range(0, height, 100):
                if (start_height + crop_size) > height:
                    break
                for start_width in range(0, width, 100):
                    if (start_width + crop_size) > width:
                        break
                    cropped_img = img[start_height : start_height + int(crop_size), start_width : start_width + int(crop_size)]

@hqq1990
Copy link

hqq1990 commented Jun 11, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants