In the crop mode of both Adobe Photoshop and Affinity Photo there is a "Straighten" tool that lets you easily straighten an image based using a a path on the image.
Affinity Photo
Here is the initial sample image
Select Crop tool and then find the Straighten option
Then draw a line along a path that you want to be straight. Be careful. If the path is more vertical then the image will rotate so the line is straight up and down. If the path is more horizontal, then the image will align so that line is straight left & right. If the image is too rotated, then you will need to an initial rotation of 90*
The image will then straighten out. Make sure to hit apply to keep the change!
Straightened version
For Photoshop
Click Crop tool and then toggle Straighten
Draw a line
The image will straighten, but may shrink the crop area.
Maybe there is a way to turn off this option (I don't use Photoshop very much). To adjust the crop. Hold the Shift + Alt and drag one of the corners.
- Shift keeps the aspect ratio the same.
- Alt keeps the crop area centered.
Image will now be straight