رَأَيْتُ عُمَرَ — «عُمَرَ» is the object and therefore accusative.
مَرَرْتُ بِعُمَرَ — «عُمَرَ» follows the preposition «بِـ» and therefore is genitive.
Method: Identify the governor and syntactic function first. The final fatḥa is identical, but the grammatical explanation is different.