Rmagik image.orientation type - ruby-on-rails

I'm trying to get the exif data from the image.
I tried to puts
1.
puts img.orientation
#TopLeftOrientation
2.
puts img.orientation
#UndefinedOrientation
How I actually can compare the value.
if i puts img.orientation.inspect
I get some values
TopLeftOrientation=1
UndefinedOrientation=0
I want to get the value of 1 to 0 ,to perform my logic, is there a way?
Besides, I found out some resource
http://blog.choonkeat.com/weblog/2007/10/lesson-1-after-.html
when:
img["EXIF:Orientation"] == "6"
it will rotate!(90)
but in my case,i got image that is "6", but it don't need to be rotate. Any ideas?

The numbers you are seeing relate to the EXIF orientation spec:
http://sylvana.net/jpegcrop/exif_orientation.html
Those map directly to these:
http://www.imagemagick.org/RMagick/doc/constants.html#OrientationType
You could simply img.orientation.to_i to get the integer value or use a case statement to derive it based on the constants in the links above.
Sometimes EXIF data is just plain wrong. So take that with a grain of salt too, that the EXIF data for some images might be flawed.
Lastly, I'm not sure if it's of use to you, but there is an img.auto_orient! which will force the image to the proper orientation for you automatically based on the EXIF data.

Related

How to create a Save/Load function on Scratch?

Im trying to make a game on Scratch that will use a feature to generate a special code, and when that code is input into a certain area it will load the stats that were there when the code was generated. I've run into a problem however, I don't know how to make it and I couldn't find a clear cut answer for how to make it.
I would prefer that the solution be:
Able to save information for as long as needed (from 1 second to however long until it's input again.)
Doesn't take too many blocks to make, so that the project won't take forever to load it.
Of course i'm willing to take any solution in order to get my game up and running, those are just preferences.
You can put all of the programs in a custom block with "Run without screen refresh" on so that the program runs instantly.
If you save the stats using variables, you could combine those variable values into one string divided by /s. i.e. join([highscore]) (join("/") (join([kills]) (/))
NOTE: Don't add any "/" in your stats, you can probably guess why.
Now "bear" (pun) with me, this is going to take a while to read
Then you need the variables:
[read] for reading the inputted code
[input] for storing the numbers
Then you could make another function that reads the code like so: letter ([read]) of (code) and stores that information to the [input] variable like this: set [input] to (letter ([read]) of (code)). Then change [read] by (1) so the function can read the next character of the code. Once it letter ([read]) of (code) equals "/", this tells the program to set [*stat variable*] to (input) (in our example, this would be [highscore] since it was the first variable we saved) and set [input] to (0), and repeat again until all of the stats variables are filled (In this case, it repeats 2 times because we saved two variables: [highscore] and [kills]).
This is the least amount of code that it takes. Jumbling it up takes more code. I will later edit this answer with a screenshot showcasing whatever I just said before, hopefully clearing up the mess of words above.
The technique you mentioned is used in many scratch games but there is two option for you when making the save/load system. You can either do it the simpler way which makes the code SUPER long(not joking). The other way is most scratchers use, encoding the data into a string as short as possible so it's easy to transfer.
If you want to do the second way, you can have a look at griffpatch's video on the mario platformer remake where he used a encode system to save levels.https://www.youtube.com/watch?v=IRtlrBnX-dY The tips is to encode your data (maybe score/items name/progress) into numbers and letters for example converting repeated letters to a shorter string which the game can still decode and read without errors
If you are worried it took too long to load, I am pretty sure it won't be a problem unless you really save a big load of data. The common compress method used by everyone works pretty well. If you want more data stored you may have to think of some other method. There is not an actual way to do that as different data have different unique methods for things working the best. Good luck.

How to capture Open3d screen without saving

I want to use the open3d image screen right away without saving it as a file.
However, the 'capture_screen_image' function provided by open3d must save the image.
(http://www.open3d.org/docs/release/python_api/open3d.visualization.Visualizer.html)
This causes the problem of having to read the saved image back to 'cv2.imread'.
I wonder if there are other ways to solve this problem or other functions provided by open3d.
I would use capture_screen_float_buffer() instead of capture_screen_image().
Remember the result is a (normalised) float numpy mat, not a typical np.uint8 typed one so depending on the use, you might also need to scale it back up to 0-255 range and cast as np.uint8:
# get the image
o3d_screenshot_mat = visualizer.capture_screen_float_buffer()
# scale and convert to uint8 type
o3d_screenshot_mat = (255.0 * np.asarray(o3d_screenshot_mat)).astype(np.uint8)
# use as required
# cv2.imshow("screenshot", o3d_screenshot_mat) , PIL.Image.fromarray(o3d_screenshot_mat , "RGB"), etc.
(e.g. if you want to visualise, remap to 0-255 range, otherwise leave data as is and simply save/load as needed)

Keeping min/max value in a BigTable cell

I have a problem where it would be very helpful if I was able to send a ReadModifyWrite request to BigTable where it only overwrites the value if the new value is bigger/smaller than the existing value. Is this somehow possible?
Note: I thought of a hacky way where I use the timestamp as my actual value, and have the max number of versions 1, so that would keep the "latest" value which is the higher timestamp. But those timestamps would have values from 1 to 10 instead of 1.5bn. Would this work?
I looked into the existing APIs but haven't found anything that would help me do this. It seems like it is available in DynamoDB, so I guess it's reasonable to ask for BigTable to have it as well https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html#API_UpdateItem_RequestSyntax
Your timestamp approach could probably be made to work, but would interact poorly with stuff like age-based garbage collection.
I also assume you mean CheckAndMutate as opposed to ReadModifyWrite? The former lets you do conditional overwrites, the latter lets you do unconditional increments/appends. If you actually want an increment that only works if the result will be larger, just make sure you only send positive increments ;)
My suggestion, assuming your client language supports it, would be to use a CheckAndMutateRow request with a value_range_filter. This will require you to use a fixed-width encoding for your values, but that's no different than re-using the timestamp.
Example: if you want to set the value to 000768, but only if that would be an increase, use a value_range_filter from 000000 to 000767, inclusive, and do your write in the true_mutation of the CheckAndMutate.

Verilog code to calculate number of rows and columns from an input image frame

I am having troubles with a verilog module which is a small part of a very big CMOS camera image code.The module takes in clk and reset as inputs and spits out hsync,vsync,pixclk and pixel data.The code reads in an image and saves it to memory and then does a a bunch of if else statements like :
if (row_count<NUM_ROWS-1) && (col_count< NUM_COLS)
begin
vsync <=1;
hsync <=1 ;
pixe_data <= mem[row_count*NUM_ROWS+col_count];
end
else if
......
Till now the image dimensions were hard coded using NUM_COLS and NUM_ROWS but I am trying to change this such that the code counts the rows and columns of the incoming image on the fly. I have tried using $fscanf,$fgets,$Sscanf etc but I am not getting the right results.In fact I am getting no results at all.My simulation gets stuck or it says its out of memory or fd is a null file descriptor.Also when I convert NUM_ROWS and NUM_COLS to be variables I get an error saying illegal operand for constant operation.
I would much appreciate if some could give me some insight into a different method to approach this problem.
My apologies in advance if the information here is insufficient or unclear.
Thanks
SK
The illegal operand for constraint operations is likely due to the dimension for mem. The dimensions needs to be a constant, e.g. reg [DATA_SIZE-1:0] mem [ROW_MAX*COL_MAX-1:0]; You'll need to decide the max image size you will process. If the max dimensions are not 2**N then you will need to implement some from of protection, e.g. signal an error and not process anything, truncate the image, or something else.
I'm not sure how to find the rows and columns of unknown image dimensions without writing custom a PLI. $fscanf can read in the image data and you will most likely want to use "%u" for format component. If image contains information about its dimentions in the file itself, then you could extract information with the $fscanf or $fread.
Other note, from your original code snip-it:
pixe_data <= mem[row_count*NUM_ROWS+col_count];
should be:
pixe_data <= mem[row_count*NUM_COLS+col_count];
Otherwise there is a risk of accessing the same data from different addresses or something out of range.

Tell Mathematica functions not to change the DataType of the parameters

I've been doing some image processing and i noticed that when i call a Mathematica function like GaussianFilter it returns an image of type "Real" even though the image i passed was of type "Byte" which causes a huge increase in memory usage.
I'm aware i can change the type of the image after the call using Image[img,"Byte"] but that is just tedious and processing overhead.
So is there a way to tell Mathematica not to change the type?
If Mma does not change the image type, you may get unexpected results. Consider (as a limit case) the binarized image of Lena:
BTW, anyone who used Lena as an example should read these two articles:
http://www.ecogito.net/articles/lena.html
http://www-2.cs.cmu.edu/~chuck/lennapg/lenna_visit.html
And optionally this one, of historical interest (not much to read, though):
(NSFW)http://www.lenna.org/full/len_full.html

Resources