No, you can't
Counterspell may only be cast "when you see a creature within 60 feet of you casting a spell" and invisibility "ends for a target that attacks or casts a spell".
Clearly for Counterspell to be effective at all you need to see a creature which is currently in the process of casting a spell. You cannot retro-actively Counterspell a spell that has already been cast by the time you see it.
Now both of these effects refer to the same action, that of casting a spell, but they have different wording. In Counterspell's rules text casting a spell starts applying as soon as the casting process begins while in Invisibility's rules text it is made clear that it is only lost after a creature casts a spell.
I believe this is intended to be interpreted to say that invisibility only ends after the spell was successfully cast. At this point it is too late to interrupt the casting. This interpretation is based on Jeremy Crawford's ruling.
Note that invisibility also ends for creatures that are casting a spell with a duration longer than 1 action, as a result of their inability to concentrate on Invisibility and their new spell simultaneously.
See? Yes. Notice? Maybe.
The rules on Hiding and stealth give a lot of leeway to a DM, so you are absolutely within your rights to declare that once a creature is looking directly at you, you cease to be hidden from it. But keep in mind a couple of important distinctions:
1. Hiding is different than being unseen
Any creature that is in a heavily obscured area, or invisible, or fighting a blinded enemy is "unseen". But a creature that is hiding is not only unseen, but also unheard, and generally unperceived. They might keep very still, or stand close to similarly colored parts of their surrounding, or compact their body so their silhouette no longer seems humanoid. In short, they are doing more than being out of line of sight.
As evidence of this distinction, consider the following on page 177 of the PHB:
An invisible creature can’t be seen, so it can always try to hide. Signs of its passage might still be noticed, however, and it still has to stay quiet.
To put it another way (and to quote a 2016 Errata in the PHB):
the question isn’t whether a creature can see you when you’re hiding. The question is whether it can see you clearly.
2. You can't Hide from a creature that sees you, but maybe you could remain hidden
The rules are clear that
You can’t hide from a creature that can see you clearly, (PHB, p. 177)
but note that this only rules out becoming hidden: it doesn't necessarily rule out remaining hidden. So as a DM, it will totally be up to you whether or not the Goblin will notice the already hidden rogue when they gain line of sight.
Keep in mind that combat is a chaotic and distracting place. As an example of what that level of chaos can do to perception, note how difficult it is to count how many passes the players in white make in this linked video.
Note, though, that once the hidden rogue attacks anything, they won't be able to hide (from the goblin) again, unless they've moved to some new location that the goblin can't see. The rules are clear that while you could remain hidden while visible, you can't hide.
3. Advantage/Disadvantage (on attacks) is not from being hidden, it is from being unseen
All the points above are meant to indicate that a creature could remain hidden while they are seen: that is, an enemy might not notice them, or might not know where they are. But that does not necessarily mean they will gain advantage on an attack roll against such an enemy.
Any place that the rules suggest a hidden creature will gain advantage on an attack, they justify this as a result of the hidden creature being unseen. Such as:
Master might allow you to stay hidden as you approach a creature that is distracted, allowing you to gain advantage on an attack before you are seen. (PHB, p. 177, bold added)
And:
When you take the Hide action, you make a Dexterity (Stealth) check in an attempt to hide, following the rules in chapter 7 for hiding. If you succeed, you gain certain benefits, as described in the “Unseen Attackers and Targets” section later in this chapter. (PHB, p. 192, bold added)
So the only real benefit a hidden character could get against an enemy that can see it is that the enemy might not notice them. This could cause an enemy to be surprised (first round of combat only) or to be unable to intentionally attack the hidden creature (because they don't know it's there). But a creature hidden in plain sight would not get advantage on attack rolls against a creature that could see them, regardless of whether or not they remain "hidden".
Best Answer
Only if the creature is hidden solely by invisibility
Being hidden simply means that other creatures are not aware of the hidden creature's current location. This doesn't always rely purely on sight, though that is most often the method used.
If Johnny is in clear view, and is sneaking up quietly from outside Billy's field-of-view, the Stealth check made is not to see if Billy spots them; that is already not possible as they are not looking in Johnny's direction. Stealth in this situation is to see if they can move quietly, without alerting Billy to their presence. If at any time Johnny were to enter Billy's field-of-view, the Stealth roll would not matter and Johnny would no longer be hidden.
Similarly, if Billy is under the effects of see invisibility, this would not change the scenario, as Johnny's Stealth relies on defeating Billy's ability to hear him approach.
If Johnny is invisible, even if Billy turns around (possibly from Johnny failing his Stealth check to move quietly), Johnny is still not visible. Billy may be able to hear him, and make an attempt to attack, but Johnny would be an unseen target due to the invisibility.
There are particular class features that do produce caveats to this, but given the general scope of your question they aren't appropriate to bring up at this time.