Whenever I take photos there is always the grueling task of orienting them correctly so that the horizon looks straight. Modern cameras do have an orientation sensor that tells you if it's a portrait or a landscape shot, but nothing more precise. Why not include a cheap orientation sensor (like the ones we have in every phone) so that the photos could later be all automatically aligned if needed? Or perhaps such cameras already exist?
My Nikon D800 had a digital artificial horizon, so yes some cameras do have this.
However, rotating images in software is absolutely a last resort as it can lead to odd moire effects and you will lose some of the periphery of the image.
Of course rotating images when using film photography at the print stage doesn't suffer from optical issues.
As is the general rule with all photography, get it right in-camera and only tweak in post if you must.
My Canon DSLR has an electronic leveller that I can enable on the LCD screen when composing an image. I'm not sure if that data gets written to the exif data of the file or not. I'm not sure if this is a mid/high end feature but it's not a new feature; it's in my 6D which was released in 2012.
Software applications like Photoshop and Lightroom and probably many others have levelling tools, including automatic modes, where they can detect lines in the image that should be horizontal or vertical.
there is always the grueling task of orienting them correctly so that the horizon looks straight
Setting the camera level doesn't necessarily make the "horizon" look straight. It works when the background is an ocean or a vast plain, but it's not uncommon to have a mountain or hill or the far shore of a lake in the background. Those may not technically be a horizons, they can still make your photo look crooked.
Beyond that, it's really not a "grueling task" to orient your photo to match the strong vertical or horizontal lines. The viewfinders in most DSLRs generally have an array of autofocus points that are visible even when not selected, and you can use several colinear AF points as a guide.
Get into the habit of asking yourself: Does the distance between the leftmost AF point and the horizon look the same as the distance between the rightmost AF point and the horizon? Or: Would a line drawn through the center column of AF points be parallel to the vertical axis of my subject's face? If you remember to look at camera orientation when you're shooting, it's pretty simple to avoid problems.
Why not include a cheap orientation sensor...so that the photos could later be all automatically aligned if needed? Or perhaps such cameras already exist?
Many do. Canon started to include electronic levels at least as far back 2011: the 6D, 60D, and T3i each have one. As far as I know, the electronic level is purely a composition aid, however; the information isn't included in the EXIF information for each image, so you couldn't use that information to automatically adjust each image afterward.
Let me start out by saying I'm an engineer not a photographer, the kinds of cameras I work with cost in the tens of millions to hundreds of millions of dollars, but I think for the purposes of this questions I might be able to help.
Often "a sensor" is cheap, but "a sensor that is accurate enough, and provides the right information" is incredibly expensive.
Most cameras probably provide a 3 Degree Of Freedom accelerometer. This means that you could get 3 acceleration vectors relative to the accelerometer (Note I did not say "what direction is down"). To determine what direction is "down" you have to do a 3 dimensional transform (not hard) and assume that the camera is not moving (also probably reasonably easy). Then you have to determine how accurate it is (was the accelerometer misaligned from the focal plane when the image was snapped? how much of that was due to factory calibration, and how much was due to post factory slippage?). Then you need to present it to the user (do you give them all three dimensions? If you give them only two dimensions how do you encode the third dimension in that?).
So in the end you have, more software (software engineers are expensive), more documentation (documentation is expensive), possibly more calibration (calibration is expensive) for a feature few people will understand or use.
Correcting an arbitrary rotation in post processing always means significant resolution loss and/or computational effort - unlike correcting 90° where you just swap the axes (and maybe even do so before compressing the image for storage - algorithms like JPEG are not totally agnostic of lines vs columns).
It is likely that a manufacturer would not only have to use an expensive sensor (mind that $5 or $10 in bill of material cost for a quality MEMS gyroscope will never just translate into $5 or $10 more on the sale price), but put enough computing power, with high power efficiency, onboard the camera if they want to sell it as a well-integrated feature. If the recomputation yields bad quality, takes several seconds or drains the battery, the camera will likely be perceived as worse quality than if the feature was not added.
Of course, it would be an option for expensive devices that had such computing power anyway to implement digital correction for interchangeable lenses.
Every digital camera I've used has had the option to superimpose crosshair lines on the display. Typically these are at the thirds, but others may also give you crosshairs at the centre. It simply is not "gruelling" to get the horizon in line with the crosshairs.
So why don't we have this? Simply because anyone capable of holding a camera steady enough to take a non-blurred photo, and of reading their camera's manual to find how to turn on the crosshairs, does not need that feature.
The last few Panasonic DMC-TZxx cameras that I have had, (technically point & shoot but very handy to have because they can be carried everywhere), have had the capability to turn on an artificial horizon on the viewfinder which makes levelling the camera, (if desired), very quick and simple.
They even change colour from Yellow to Green when you have a level.