“the detestable things that are before his eyes.” The Hebrew text reads, “detestable things of his eyes,” that is, that he sees or looks at. The NIV nuances the text but makes it clear: “get rid of the vile images you have set your eyes on.” This context shows that those things were idols.
“do not defile yourselves with the idols of Egypt.” The books of Moses do not specifically refer to the Israelites worshiping idols while they were in Egypt, but it is apparent they did. They had barely left Egypt when they desired to have gods made, and made a golden calf (Exod. 32:1-4). Also, according to Joshua 24:14 the Israelites still had gods with them they had worshiped in Egypt.