Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
this is my very first stackoverflow question.
I'm not a native speaker, but I study mainly in english, and I've tried to search this around the internet with different approaches to my text but I couldn't find anything.
And i'm having trouble to find some directions to write a simple code that follows something like this:
example:
We have a set of values, for example, characters from a game, or flags from a country, etc.
Suposing we have three flags: Japan, Usa and Israel.
We inform to the user these values, so then he knows what are the possible picks, and choose one.
Then, the algorithm make questions like: "Is the blue color present in this flag? yes or no?"
(if the answer is yes, than the algorithm eliminates Japan, for example)
Then the algorithm make some more pertinent questions until just one flag is left.
"You chose the flag of United States."
I know stackoverflow maybe it's not intended for such simple and beginner questions, but if I could have any clue on how to develop this simple algorithm maybe it would help me on how to apply if statements and things like that into my codes and my current ideas. I'm learning Python and Math by myself currently, and every small step is very enlightening.
If someone could fill me in with some Python structure for this or, or pseudocode, or even what phrase should I google, it would mean a lot to me.
Sorry for my bad english!
I think you have to prepare a list of questions first, then with each question, you will have a list of remaining answers. After asking a bunch of questions, you will get the final answer as you wish.
For example, I will have a dictionary storing questions for the flag examples above:
list_options = [{'q': 'does the blue present in the flag?', 'y':['israel'], 'n': ['japan', 'usa']}, {'q': 'is the circle in the flag?', 'y': ['japan'], 'n': ['usa']}]
So at each step, you throw a question to the user and eliminate some answers until you get the last one.
Hope this could help
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
I want to design a load of pixel art crabs (crabs are just an example) in different colours with different backgrounds, claws, gloves, eyes etc.
The way I envision it is that I would draw multiple assets that a program will stick together randomly and check if it’s the same as another it’s already generated. I assume it would be put together via a grid (one section of the grid will always be a claw but it will a randomly selected by the program for example. All the other sections of the grid will be for one specific part of the body as well).
I have no idea how to do this or where to start. I’m quite new to coding so I’m really looking for advice. How can I achieve this? What are some good key words to search for tutorials that might help? What libraries or anything will I need to use to have my code create the pictures? How do I link the drawn assets to the code? How do I get the code to export the generated designs to a folder? And anything else you know I’ve missed!
The pixel art will just end up being art, not game assets or anything.
Thanks a lot for reading and also thanks a lot for any help! Much appreciated! I know this is very noob stuff and I’m more than willing to put in the work, I just need some guidance from you guys!
Basically, you would write code to read from the original images, them paste them together into new images.
The processing programming language is a great tool when coding for artistic purposes: https://processing.org/
You may take a look at this list of articles and tools for creative coding: https://github.com/terkelg/awesome-creative-coding
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I learnt about DRY code and
Flat is better than nested
I also know that excessively DRY code is bad and I am not "religiously" DRY or anything. But which of these would be better? (I can't make out as the creator what might be less readable)
"""
Basically the variable "answer" is overwritten to equal "number" "+" or "-"
or "*" or "/" or "**" the existing value of answer. Here, operation is a
dictionary; and a value (such as to add, subtract etc.) is accessed based on
symbol the user has inputted (such as "+", "-" etc.)
"""
#Type 1:
number = float(input("Enter number: "))
answer = operation[symbol](answer, number)
#Type 2:
answer = operation[symbol](answer, (float(input("Enter number: "))))
Its greate that you think about software quality right from the start. The best answer is not always very clear, and especially if you consider a decision on a very low level of a single instruction call, as you do now.
I would vote for Type1, but Type2 is also entirely OK. This is dependent on person's habits that develop over time.
I think you can go with any of them for now, but still consider best practices and design patterns when thinking about the overall shape of your program. The goal is for software to be easily maintainable and (in case you create a library) easy to use by other programmers.
This example is not so complicated, so type 2 would be Okay (but meh) for me, but overall I would go for type 1 because I think it is more readable. Not just for me, but also for everyone else who will be working with my code later. I don't like the multiple actions in one line, I think it makes things unnecessarily complicated when you (or someone else) come back to it later
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm making an image recognition program in python 3, I've got as far as getting the name of the item if it isn't recognised, the path of the image to search, and I've used PIL to return the RGB values of each pixel. However: now that I've actually got to the pattern recognition, I have no idea how to attempt it. It's not a problem of errors in the code, or a lack of understanding to attempt this (this is the best way for me to learn programming languages), it's that I don't know what to program (the logic behind it, if you will).
Please note:
I'm not looking for any code, purely just an explanation of the logic behind it. (I know that this may not be the right place to ask, but since it was sort of a programming question, I decided it was ok)
This has been puzzling me and my programming friends for a few days now, so any help would be greatly appreciated.
You should give a try to OpenCV and Template Matching approach. There are more sophisticated algorithms such Feature Matching. It depends on the situation.
Try using OpenCV. An example algorithm can be:
Extract keypoints and features from your template using feature detector (ORB, Sift, Surf)
Do the same for the image
Compare keypoint descriptors (e.g. for ORB using BFMatcher)
Compare count of matched keypoints with your selected threshold
The logic behind this is actually quite simple. I googled a bit around and I found out it works like this:
You need to compare all pixels to the pixels in the pattern you need to compare, then just create a var which is set to False when a pixel doesn't match. As soon as this happens, the comparing function is stopped(You could use a while True: function with a break statement in it) and returnes False then. If it matches, there will be no set to 'False' and the variable of the beginning will stay True.
I hope I could give you an Idea of what to do.
Sincerely, heureka
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Perhaps this is not the correct place to ask this question, and part of me thinks that there is no real answer to it, but I'm interested to see what experienced Python users have to say on the subject:
For maximum readability, concision, and utility, what is a range for an optimal length of a Python function? (Assuming that this function will be used in combination with other functions to do something useful.)
I recognize that this is incredibly dependent on the task at hand, but as a Sophomore Comp. Sci. major, one of the most consistent instructions from professors is to write programs that are comprised of short functions so as to break them up into "simple", discrete tasks.
I've done a big of digging, including through the Python style guide, but I haven't come up with a good answer. If there are any experienced Python users that would like to weigh in on this subject, I would appreciate the insight. Thanks.
I'm sure a lot of people have strong opinions about this, but for new programmers a good rule of thumb is to try and keep it below 10-20 lines. A better rule of thumb is that a function should do one thing and do that one thing well. If it becomes really long, it is likely doing more than one thing and can be broken down into several functions.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to know whether it is possible to carry out such an operation, that one picture is placed into another one at exact coordinates, automatedly.
I have a set consisting of 20 pairs of images of fixed size. I need to merge the pairs by placing first image of a pair to a fixed position on the second image.
I might need to do this mergers several times in future, so I am interested if there is a chance to write a scrypt in Python/Perl or any other simple language to handle this task. I am now using GIMP scripts, but most of the work still needs to be carried out manually...
Anyway, if this is not an option, I am asking someone to be so kind and briefly explain why is it so.
Thanks!
a lot of recepies ImageMagick v6 Examples -- Compositing Images. And you need perl-magick.